laravel delete where code example

Example 1: laravel force delete

Product::find($id)->forceDelete();

Example 2: laravel delete where

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

Example 3: laravel delete

DB::table('users')->where('votes', '>', 100)->delete();

Example 4: Laravel Delete

Flight::destroy(1);

Flight::destroy(1, 2, 3);

Flight::destroy([1, 2, 3]);

Flight::destroy(collect([1, 2, 3]));

Example 5: laravel eloquent remove from db

public function destroy($id){

  $res=User::find($id)->delete();
  if ($res){
    $data=[
    'status'=>'1',
    'msg'=>'success'
  ];
  }else{
    $data=[
    'status'=>'0',
    'msg'=>'fail'
  ];
  return response()->json($data);

Example 6: larave Soft Deletes

Schema::table('flights', function (Blueprint $table) {
    $table->softDeletes();
});

Tags:

Misc Example