0
@foreach($tasks as $t)
{{$t->id}} // works fine
{{$t->client->last_active}} // Trying to get property of non-object
{{$t->client()->last_active}} // something similar error.
@endforeach
鑑於以下數據結構,我如何訪問相關模型的last_active
字段?如何訪問分頁內的相關模型(Laravel 5.1)
任務:
public function client(){
return $this->belongsTo('\App\Client');
}
客戶:
public function tasks()
{
return $this->hasMany('App\Task');
}
向我們展示「Task」和「Client」模型的相關代碼。 – sepehr
問題已更新 –