0
朋友你好需要一隻手與此查詢,未能使其工作,我是新與laravel,我有3種型號:與laravel動態查詢4
DiscussCategory
class DiscussCategory extends Eloquent {
protected $table = 'discuss_category';
protected $guarded = array('id');
public function status() {
return $this->belongsTo('Status');
}
public function discuss() {
return $this->hasMany('Discuss');
}
}
討論
class Discuss extends Eloquent {
protected $table = 'discuss';
protected $guarded = array('id');
public function discussReplies() {
return $this->hasMany('DiscussReplies');
}
public function discussCategory() {
return $this->belongsTo('DiscussCategory');
}
public function users() {
return $this->belongsTo('Users');
}
}
用戶
class Users extends Eloquent {
protected $table = 'users';
protected $guarded = array('id');
protected $hidden = array('password');
public function getAuthIdentifier() {
return $this->getKey();
}
public function getAuthPassword() {
return $this->password;
}
public function getReminderEmail() {
return $this->email;
}
public function discussReplies() {
return $this->hasOne('DiscussReplies');
}
public function discuss() {
return $this->hasMany('Discuss');
}
}
,這我如何努力,以顯示查詢鑑於
@foreach($data as $category)
{{$category->discuss->last()->users->nickname}}
@endforeach
如果你運行一個foreach設法獲取用戶,但我只想要最後一位用戶的姓名發表討論
Trying to get property of non-object
appreciate a hand, insurance is not much, but I have little experience