Answers for "laravel eloquent sync"

PHP
2

associate laravel

When updating a belongsTo relationship, you may use the associate method. This 
method will set the foreign key on the child model:

	$account = AppAccount::find(10);
	$user->account()->associate($account);
	$user->save();

When removing a belongsTo relationship, you may use the dissociate method. This
method will set the relationship foreign key to null:

	$user->account()->dissociate();
	$user->save();
Posted by: Guest on December-07-2020
0

sync laravel

$user = User::find(1);

$user->roles()->detach([1, 2, 3]);

$user->roles()->attach([
    1 => ['expires' => $expires],
    2 => ['expires' => $expires],
]);
Posted by: Guest on February-08-2021
0

laravel model sync

$user->roles()->sync([1, 2, 3]);
Posted by: Guest on May-08-2021
0

latavel attach method

$user->roles()->attach($roleId, ['expires' => $expires]);
Posted by: Guest on December-30-2020

Browse Popular Code Answers by Language