Laravel delete where condition

Updated at 22-Aug-2022, By samar

Laravel delete where condition

With this article, we’ll look at some examples of how to address the "Laravel delete where condition" problem.

You can delete the records from users table using where condition.

Basically where condition filter the data and delete the records. Like if you want to delete all the records except the record of user id 1 than you can use where('id', '>', 1)->delete() to delete the record.

  • $deleted = DB::table('users')->where('id', '>', 1)->delete();
    

    This query will delete all the users records except the user id 1.

    Import DB facade in controller class after namespace

    use Illuminate\Support\Facades\DB;
    

Back to code snippet queries related laravel