laravel with trashed code example
Example 1: laravel with trashed
$flights = App\Flight::withTrashed()
->where('account_id', 1)
->get();
Example 2: force delete soft delete laravel
Soft Delete : $user->delete();
Force Delete : $user->forceDelete();
Restore Soft Deleted Item : $user->restore();
Example 3: laravel update from query
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
Example 4: 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 5: laravel query with trashed
$user->roles()->withTrashed()->get();