0
我試圖讓我的訂閱數據透視表的工作,但我一直ketting此錯誤:Laravel morphTo關係
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'subscription_type' in 'field list' (SQL: update `topic` set `updated_at` = 2016-10-02 18:06:49, `subscription_type` = App\Square\Users\User, `subscription_id` = 1 where `id` = 1)'
所以我有3個表:
User
Subscription
Topic
用戶可以訂閱一個主題。這是認購表的樣子:
Schema::create('subscription', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->index();
$table->integer('subscription_id');
$table->string('subscription_type');
$table->timestamps();
$table->unique(['user_id', 'subscription_id', 'subscription_type']);
});
我在User
模型關係:
public function subscriptions()
{
return $this->morphMany(Subscription::class, 'subscription');
}
所以,當我嘗試這php artisan tinker
:
App\Square\Users\User::first()->subscriptions()->save(App\Square\Topics\Topic::first());
我收到錯誤!我究竟做錯了什麼? (我需要這個多態表,因爲我必須用它來做更多的事情)