我創建一個回覆模型,然後試圖返回的對象與它的主人關係後負荷()。這裏是一個返回一個空對象的代碼:laravel預先加載()與創建父模型
//file: Thread.php
//this returns an empty object !!??
public function addReply($reply)
{
$new_reply = $this->replies()->create($reply);
return $new_reply->with('owner');
}
然而,如果我交換用()爲負載()的方法方法加載所有者關係,我得到預期的結果。也就是說,返回它的回覆對象的相關所有者關係:
//this works
{
$new_reply = $this->replies()->create($reply);
return $new_reply->load('owner');
}
我不明白爲什麼。尋找澄清。
感謝, Yeasir
https://stackoverflow.com/questions/26005994/laravel-with-method-versus-load-method這裏有一個很好的問題 – Sohel0415