My guess was to use the following syntax:

MyModel::all()->delete();

But that did not work. I'm sure it's super simple, but I've searched for documentation on the subject and can't find it!

推荐答案

The reason MyModel::all()->delete() doesn't work is because all() actually fires off the query and returns a collection of Eloquent objects.

您可以使用truncate方法,这适用于Laravel 4和5:

MyModel::truncate();

That drops all rows from the table without logging individual row deletions.

Laravel相关问答推荐

Uncaught ReferenceError:未定义require[Shopify PHP React Browser问题]

用Laravel Filament创建变形组件

工厂多对多数据透视表属性

LARVAL SAVE 中的关系有

Laravel 模型事件:delete() 不会从存储中删除文件

仅针对字母的 laravel 验证规则

Laravel 如何处理来自浏览器的 PUT 请求?

我在哪里放置事件侦听器和处理程序?

合并两个 Eloquent 集合并删除所有重复项.

升级到 laravel 5.4 后调用未定义的方法

如何在没有 Eloquent 的情况下创建 Laravel 模型?

Laravel 5 - Php artisan语法错误

导航栏品牌中的 Laravel 动态页面标题

如何在 Laravel 中使用旧输入重定向?

干预图像:直接从带有原始文件名和分机的网址保存图像?

Laravel 5 Mime 验证

如果 Laravel 中的值不为空,如何验证输入字段

调用未定义的方法 Illuminate\Routing\Route::get()

Laravel - 动态创建表(无需迁移)

Laravel 5 Illuminate\Http\Request 的方法不允许静态调用