私は多くの関係でピボットテーブルにアクセスするこのコントローラを持っています。ピボットテーブルの列は値で、created_atです。私は(あなたがクエリから配列を返す必要がある場合は、あなたの代わりにselect()
laravel、配列を返すようにコードを変更する方法は?
$o_response = $this->statuses()->where('status_id', $o_health_status->id)
->pluck('values','created_at')->orderBy('created_at','ASC');// ->first();
//I think you no need to use ->first(); here.
Docsのpluck()
を使用することができ、このコントローラは、私の値の配列を返すとlaravelで
public function status($s_type)
{
$o_health_status = Status::where('name', 'health')->first();
$o_speed_status = Status::where('name', 'speed')->first();
if ($s_type === 'health'){
$o_response = $this->statuses()->where('status_id', $o_health_status->id)
->select('values','created_at')->orderBy('created_at','ASC')->first();
if($o_response === null){
return 'unsigned';
}
$o_response = $o_response->values;
return $o_response;
}else{
$o_response = $this->statuses()->where('status_id', $o_speed_status->id)
->select('values','created_at')->orderBy('created_at', 'desc')->first();
if($o_response === null){
return 'unsigned';
}
$o_response = $o_response->values;
return $o_response;
}
あなたが何を求めているのかははっきりしていません。同じ理由で – manniL