laravel delete query eloquent code example

Example 1: force delete soft delete laravel

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

Example 2: laravel delete where

DB::table('users')->where('id', $id)->delete();

Example 3: laravel update from query

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

Example 4: laravel fillable

/**
     * The attributes that are mass assignable.
     */
    protected $fillable = [
      					   'title',
                           'slug',
                           'body',
                           'image',
                           'published',
                           'comments_open'
                          ];

Example 5: laravel query with trashed

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

Example 6: laravel update

<!-mass update-->
App\Models\Flight::where('active', 1)
          ->where('destination', 'San Diego')
          ->update(['delayed' => 1]);

Tags:

Misc Example