Copy cascade in Laravel

-1

Good afternoon,

Let's say that I want to cascade a user with all its contents present in other tables. These tables linked to users.

User   - Favorite pages   - Services

In laravel, how could that user and his linked tables be copied. That is, as a cascade copying.

Regards,

    
asked by Angel Prieto 14.12.2017 в 15:08
source

1 answer

0

I recommend that you create a restriction of " external key " for this case. Also, since it is a many-to-many relationship, you can use the detach () method in your Eloquent model (if the relationships were correctly established in your user and in your models).

$user = App\User::find(1);
// Detach all roles from the user...
$user->roles()->detach();

You can see the documentation for for more details .

p>     
answered by 29.12.2017 в 15:00