add data to laravel many to many relationship
1. $user->roles()->attach($roleId);
2. you may also pass an array of additional data to be inserted
$user->roles()->attach($roleId, ['expires' => $expires]);
3. // Detach a single role from the user...
$user->roles()->detach($roleId);
4. // Detach all roles from the user...
$user->roles()->detach();
5. Any IDs that are not in the given array will be removed from the intermediate
table
$user->roles()->sync([1, 2, 3]);
6. If you need to update an existing row in your pivot table, you may use
updateExistingPivot method. This method accepts the pivot record foreign
key and an array of attributes to update:
$user->roles()->updateExistingPivot($roleId, $attributes);
Also in PHP:
- can you use return in catch php
- char uppercase php
- composer and php version
- echo day php
- array key exists php after submit
- failed to clear cache laravel
- date - Manual - PHPwww.php.net › manual › function.date.phpdate ( string $form
- encryption and decryption in php example
- enable php errors
- clear cache laravel project
- db seed specific seeder
- disable timestamps laravel
- after create a new laravel project and copy old project on it how insatall all packages
- PHP detect spam name
- dump all variables twig
- factoring and seeding in laravel
- composer cache clear
- converting strings to uppercase in php
- create directory in directory php
- exceptions php
- default header value in php
- add 2 days in php
- date("l",$date) php
- apache php e_warnings e_notice off