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 :: Downward half-Pyramid Pattern of Star 
Php :: Symfony 5 - Customize Twig error templates 
Php :: Two ways of assigning anonymous class to a variable 
Php :: codeingniter 3 not like 
Php :: how to add in massive php 
Php :: saleor meaning 
Php :: expresions 
Php :: How to add logo in FPDF PHP 
Php :: refresh database tables yii 1 
Php :: doiffernce between text and string in laravel migration 
Php :: verta sample jalali laravel problem return object 
Php :: codeception send text in ckeditor 
Php :: wc php get order get coupon discount amount 
Php :: split php 
Php :: Returning JSON from a PHP Script 
Php :: hide .php 
Php :: laravel array update 
Php :: laravel validation 
Php :: phpunit/phpunit[6.0.0, ..., 6.5.14] require php ^7.0 - your php version (8.0.0) does not satisfy that requirement. 
Php :: json decode php array 
Php :: laravel carbon y-m-d 
Php :: ERROR: The following modules depend on mpm_prefork and need to be disabled first: php7.2 
Java :: java create directory if not exists 
Java :: left fold java 
Java :: javafx dependency 
Java :: java program to calculate age from date of birth 
Java :: javafx tableview remove all rows 
Java :: bucket sort java 
Java :: listview get selected java 
Java :: set height of layout programmatically android 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =