HDTuto.com

Laravel - Delete all records from table query


Do you require to delete all data from table using laravel eloquent? If yes then you can get a solution for your problem. We can easily remove all records from table using DB class with delete().

But if you need to destroy all records using laravel eloquent model then how you will do it?, Actually i cache my all records and when someone remove that records then automatic remove from cache too. but it is possible if you are doing with laravel eloquent model. So is there method truncate() with eloquent but it is not working for me, so finally i found solution for delete all records from database table using following way.

Just check bellow all example and i hope it will work for you:

Solution 1:

User::truncate();

Solution 2:

User::whereNotNull('id')->delete();

Solution 3:

User:where('id', 'like' '%%')->delete();

Solution 4:

DB::table('users')->delete();

I hope you found your solution....






July 5, 2018 | Category : PHP Laravel Laravel 5
Related Posts