laravel with trashed
snippet in php

laravel with trashed

user9025

$flights = App\Flight::withTrashed()
                ->where('account_id', 1)
                ->get();

force delete soft delete laravel

user2971

Soft Delete : $user->delete();
Force Delete : $user->forceDelete();
Restore Soft Deleted Item : $user->restore();

laravel update from query

user1807

$affected = DB::table('users')
              ->where('id', 1)
              ->update(['votes' => 1]);

laravel query with trashed

user1727

$user->roles()->withTrashed()->get();

laravel firstorcreate

user2536

// Retrieve flight by name, or create it if it doesn't exist...
$flight = App\Flight::firstOrCreate(['name' => 'Flight 10']);

// Retrieve flight by name, or create it with the name, delayed, and arrival_time attributes...
$flight = App\Flight::firstOrCreate(
    ['name' => 'Flight 10'],
    ['delayed' => 1, 'arrival_time' => '11:30']
);

// Retrieve by name, or instantiate...
$flight = App\Flight::firstOrNew(['name' => 'Flight 10']);

// Retrieve by name, or instantiate with the name, delayed, and arrival_time attributes...
$flight = App\Flight::firstOrNew(
    ['name' => 'Flight 10'],
    ['delayed' => 1, 'arrival_time' => '11:30']
);