Hi,
I have a Venue and Event table.
A Venue can have many Event(s).
An Event belongs to many Venue(s).
...
I have a pivot table venues_events
The migration is as follow:
$table->increments('id');
$table->integer('venue_id')->unsigned();
$table->integer('event_id')->unsigned();
$table
->foreign('venue_id')
->references('id')
->on('venues')
->onDelete('cascade');
$table
->foreign('event_id')
->references('id')
->on('event')
->onDelete('cascade');
$table->timestamps();
For now I'm working with an sqlite database and I think I will stick with this solution because the project is very small...
My very first question is how to achieve a cascade delete on the pivot table when I delete an event or a venue? When I perform $item->delete() it won't cascade.
I googled (I'm not sure) but it seems sqlite doesn't manage very well cascading... (Correct me if I'm wrong).
I continued googling and found eloquent events results...
Because I'm running with Laravel 5.1 I think the eloquent events term is not anymore appropriate (correct me if I'm wrong).
Instead I think I can use Laravel events /listenners. Is this the right way?
Is there some other technics?
Should I use detach() before deleting my item?
Please share the best practice for a simple situation like mine.
Thank you :)