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
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
xxxxxxxxxx
$user = User::updateOrCreate(
['name' => request()->name], //Try to match this
['foo' => request()->foo] //Data to be created/updated including the first parameter
);
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
$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
<?php
// Example 1
public function example(){
Table:update([
'example_column' => [
'field1' => $value1,
'field2' => $value2,
]
]);
}
// Expected result in your table with column named 'example_column' :
{'field1' : $value1, 'field2' => $value2}
// Example 2
public function example(){
Table:update([
'example_column' => [
'field1' => [
'inside_field1': $value1,
'inside_field2': $value2,
]
]
]);
}
// Expected result in your table with column named 'example_column':
{
field1: {
inside_field1: $value1,
inside_field2: $value2,
}
}
xxxxxxxxxx
DB::table('vendor_managements')->where('vendor_code', $vendor_code)->update(array('state'=> $state_namne));