jeudi 3 septembre 2015

Laravel 5 setup model event to "clear up" pivot tables on model delete

I am using Laravel 5 to build a user based application. Some models have a manyToMany relationship in my app and therefore I am using pivot tables.

When I delete a user from the system, I use this simple function:

/**
 * Delete user.
 *
 * @param $id
 * @return mixed
 */
public function deleteUser($id)
{
    return $this->user->whereId($id)->delete();
}

However, when the user is deleted, the rows in the pivot tables (for example role_user) do not get deleted.

I have read on the laravel site that I can use model events to "clear up" my pivot tables, but i'm really unsure how I would implement that.

Can anyone point me in the right direction?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1LNeLgM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire