Delete All Rows for a Laravel Model

laravel
Table of Contents

There are 2 way to delete all of the records for a model.

  1. Model::truncate()

This is perfect for when you don't need to modify which records are being deleted and just want to delete all of them.

Post::truncate();
  1. Model::query()->delete()

If you wanted to add some constraints onto the deletion, you'd likely want to use this method. The ::query() method just returns a new Builder instance, so you can chain you extra methods with, some, intellisense.

Post::query()
    ->delete();

Post::query()
    ->where('created_at', '<', now()->subYear())
    ->delete();

Enjoyed this post or found it useful? Please consider sharing it on Twitter.