Truncate a table in Laravel 5

From the Laravel Docs

https://laravel.com/docs/5.6/queries#deletes says:

If you wish to truncate the entire table, which will remove all rows and reset the auto-incrementing ID to zero, you may use the truncate method:

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


The truncate method is part of the Query Builder. However Visitor::all() returns a Collection instance. You need to build the query using the following:

Visitor::query()->truncate();

the following should work as well,

Visitor::truncate();


Laravel 8.0 docs

https://laravel.com/docs/8.x/queries#delete-statements

With query builder:

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

And with model:

User::truncate();