I have a question regarding saving polymorphic relationships in Laravel. This is the model i would like to create in laravel.
A shop has many products, and a product can be either an "item" an "event" or a "service".
I have the following tables:
- shops
- id
- user_id
- name
- events
- id
- public
- title
- description
- products
- id
- shop_id
- productable_id
- productable_type
This is how i set up the models:
class Shop extends Model{
public function products(){
return $this->hasMany('App\Product');
}
}
class Product extends Model{
public function productable(){
return $this->morphTo();
}
}
class Event extends Model{
public function product(){
return $this->morphOne('App\Product','productable');
}
}
I want to be able to do the following:
$shop = Shop::first()
$event = Event::create(['title'=>'Some event']);
$service = Service::create(['title' => 'Some service']);
$shop->products()->save($event);
$shop->products()->save($service);
But it doesn't work! When i try to save the relation i get:
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1 no such column: shop_id (SQL: update "accendo_events" set "updated_at" = 2016-11-26 10:11:02, "shop_id" = 1 where "id" = 1)'
Anyone have an idea of where this is going wrong? I probably misunderstood something about this type of relationship...

$shop->products()->create($event);- Sherif$product->create($event);- Sherif