Laravel delete where condition

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.