這是我的博文模型。 class Post extends Model
{
use SoftDeletes;
protected $table = 'posts';
protected $fillable = ['title','featuring_image', 'brief', 'body', 'seen_count'];
public functi
我有一個變形關係,主體可以有多個關係。它們的存在取決於變形的模型。我需要檢索所有相關模型(whereHas()不能解決問題),並且如果它們存在於特定模型上(with()將不起作用,因爲關係不總是存在),我希望它們的關係被加載。 還有什麼其他內置的東西可以用來流暢地解決這種情況,或者黑客是唯一的解決方法嗎? <?php
...
class Post extends Model
{
我創建一個回覆模型,然後試圖返回的對象與它的主人關係後負荷()。這裏是一個返回一個空對象的代碼: //file: Thread.php
//this returns an empty object !!??
public function addReply($reply)
{
$new_reply = $this->replies()->create($reply);
r