update or create in laravel code example
Example 1: create or update in laaravel
$data = $request->all();
UserRule::updateOrCreate(
['id' => 1],
$data
);
Example 2: laravel updateOrCreate
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
Example 3: update or create laravel
$user = User::updateOrCreate(['name' => request()->name], [
'foo' => request()->foo
]);
Example 4: laravel fillable
protected $fillable = [
'title',
'slug',
'body',
'image',
'published',
'comments_open'
];
Example 5: laravel firstorcreate
$flight = App\Flight::firstOrCreate(['name' => 'Flight 10']);
$flight = App\Flight::firstOrCreate(
['name' => 'Flight 10'],
['delayed' => 1, 'arrival_time' => '11:30']
);
$flight = App\Flight::firstOrNew(['name' => 'Flight 10']);
$flight = App\Flight::firstOrNew(
['name' => 'Flight 10'],
['delayed' => 1, 'arrival_time' => '11:30']
);
Example 6: update query in laravel eloquent
$data = DB::table('cart')
->where('crt_id', $id)
->update(['crt_status' =>'0']);