0
我已經做過很多次,但不知何故我的心是停留在這一個:
$data['conversations'] = Conversation::with("sender")->received()->get();
做{{ $conversation }}
產生:
{
"id": "1",
"subject": "",
"sender": {
"id": "4",
"email": "[email protected]",
"name": "Jane Poe",
"group_id": "3",
"created_at": "2014-12-22 20:31:00",
"updated_at": "2014-12-22 20:31:00"
},
"receiver": "1",
"created_at": "2015-01-04 00:00:00",
"updated_at": "2015-01-04 00:00:00"
}
注意,「發件人現在{{ $conversation->sender->email }}
給出:
試圖獲得非物件的財產
當致電{{ $conversation->sender }}
時,它僅打印「4」(id)。
發件人存儲在對話中表中列名爲發件人。
$conversation->sender()
沒有工作,要麼
這是代碼:
class Conversation extends Eloquent {
protected $table = 'conversations';
public function sender()
{
return $this->belongsTo('User','sender','id');
}
public function receiver()
{
return $this->belongsTo('User','receiver','id');
}
}