laravel eloquent insert code example
Example 1: laravel updateOrCreate
$flight = App\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
Example 2: laravel insert
DB::table('users')->insert([
'email' => '[email protected]',
'votes' => 0
]);
Example 3: laravel delete where
DB::table('users')->where('id', $id)->delete();
Example 4: laravel fillable
protected $fillable = [
'title',
'slug',
'body',
'image',
'published',
'comments_open'
];
Example 5: laravel eloquent get first
$user = App\User::where('id',$id)->first();
$userId = App\User::where(...)->pluck('id');
Example 6: laravel create or update
$flight = App\Models\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);