我試圖建立一個多態的一對一關係(has_one和belongs_to的多態等價物)。我有一個Address
模型,還有其他幾個模型我想擁有一個地址。但是,我對文檔的措辭感到困惑。我已經看到了morphMany
方法,但我的問題是:我應該使用morphMany
,即使我只希望它有一個地址,或者是否有像我應該使用的morphOne
方法?Laravel雄辯多態一對一?
編輯:我的Address
模型具有這些領域,只是爲了幫助形象化:
Schema::create('addresses', function ($table)
{
$table->increments('id');
$table->string('street');
$table->string('street_more')->nullable();
$table->string('city');
$table->string('state')->nullable();
$table->string('country');
$table->string('postal_code');
$table->integer('addressable_id');
$table->string('addressable_type');
});
這不是模型。這是遷移。 –
@丹尼斯布拉加我指的是模型的結構。感謝您的支持!我已在帖子中澄清過。 – BenjaminRH