xxxxxxxxxx
$newUser = \App\UserInfo::updateOrCreate([
//Add unique field combo to match here
//For example, perhaps you only want one entry per user:
'user_id' => Auth::user()->id,
],[
'about' => $request->get('about'),
'sec_email' => $request->get('sec_email'),
'gender' => $request->get("gender"),
'country' => $request->get('country'),
'dob' => $request->get('dob'),
'address' => $request->get('address'),
'mobile' => $request->get('cell_no')
]);
xxxxxxxxxx
//if there is id => 1 for user role , update this and if there is not
//id => 1 create it and insert some data for it
$data = $request->all();
UserRule::updateOrCreate(
['id' => 1],
$data
);
xxxxxxxxxx
$user = User::updateOrCreate(
['name' => request()->name], //Try to match this
['foo' => request()->foo] //Data to be created/updated including the first parameter
);
xxxxxxxxxx
// Newer version of PHP
$user = User::updateOrCreate(
['email' => request('email')],
['name' => request('name')]
);
// Older version of PHP
$user = User::where('email', request('email'))->first();
if ($user !== null) {
$user->update(['name' => request('name')]);
} else {
$user = User::create([
'email' => request('email'),
'name' => request('name'),
]);
}
xxxxxxxxxx
$user = User::updateOrCreate(
['email' => request('email')],
['name' => request('name')]
);
// Do other things with the User
xxxxxxxxxx
// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
xxxxxxxxxx
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
// updates price and discounted or creates a new record
xxxxxxxxxx
use App\Models\Flight;
$flight = Flight::find(1);
$flight->name = 'Paris to London';
$flight->save();
xxxxxxxxxx
DB::table('vendor_managements')->where('vendor_code', $vendor_code)->update(array('state'=> $state_namne));