mardi 27 février 2018

Laravel Model Restore Event

So I have 2 Models Users & Staff. They have one to one relationship with one another.

User.php 'hasOne' Staff AND Staff.php 'belongsTo' User

When I Soft Delete a User I want to soft delete Staff entry as well, I have achieved this using(Works Perfectly):

static::deleting(function ($user) {
    $user->staff()->delete(); 
});

Now I want to restore the staff when I restore the User for that I have tried using this(Not working):

static::restoring(function ($user) {
    $user->staff()->restore();
});

But this is not working. The User Entry is deleted but the Staff entry still remains soft deleted.

  • Can someone help me understand what I am doing wrong here?

  • Also, Is this the best way to get this done? Or is there some other way this should be done?

PS: I'm using Laravel 5.5



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

Aucun commentaire:

Enregistrer un commentaire