【发布时间】:2017-01-16 20:52:36
【问题描述】:
@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 字段?
任务:
public function client(){
return $this->belongsTo('\App\Client');
}
客户:
public function tasks()
{
return $this->hasMany('App\Task');
}
【问题讨论】:
-
向我们展示
Task和Client模型的相关代码。
标签: php pagination laravel-5.1