Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel many to many relationship with pivot table

$user = User::find(1); //any user we want to find 
$user->trophies()->attach($idOfTrophy); 
//pass id or array of a Trophy ids 
//suppose admin has selected the trophy from a form and trophy id
// is in $request object, then.
$trophyId = $request->trophy_id;
$user->trophies()->attach($trophyId); //record is created in DB.
attach and syncWithoutDetaching both does same job
Comment

laravel many to many relationship with pivot table

$user = User::find(1); //any user we want to find $user->trophies()->attach($idOfTrophy); //pass id or array of a Trophy ids //suppose admin has selected the trophy from a form and trophy id// is in $request object, then.$trophyId = $request->trophy_id;$user->trophies()->attach($trophyId); //record is created in DB.attach and syncWithoutDetaching both does same job
Comment

PREVIOUS NEXT
Code Example
Php :: pcntl php 
Php :: Best version control tools for php 
Php :: wordpress how to string multple function.php files together 
Php :: laravel add params form submission 
Php :: symfony retun json 
Php :: laravel left join count 
Php :: select all matched text phpstrom 
Php :: select query with multiple where clause in php 
Php :: laravel eloquent where if a variable has value 
Php :: thems 
Php :: phphtml 
Php :: remove elements to this array 
Php :: remove public path from url laravel 
Php :: how to concatenate folder name with image in php 
Php :: Query without chaining not working - Laravel 
Php :: Laravel A row must be an array or a TableSeparator instance. 
Php :: wordpress curl wp remote post timeout error 
Php :: org.springframework.web.context.request.async.AsyncRequestTimeoutExceptionTimeoutDeferredResultProcessingInterceptor 
Php :: Josn_encode php api encoding issue 
Php :: get all routes in laravel 
Php :: laravel-filemanager not working 
Php :: xampp pdoexception could not find driver 
Php :: laravel task scheduler error 
Php :: how to convert php code to a string 
Php :: faire un fichier zip en php 
Php :: php array merge 
Php :: onde fica o php ini ubuntu 
Php :: return user details from controller to view 
Php :: laravel allow null records relationship 
Php :: how to download file in laravel 8 delelete from directry 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =