How to delete all the rows in a table using Eloquent?

前端 未结 14 2068
鱼传尺愫
鱼传尺愫 2021-01-30 09:35

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

14条回答
  •  伪装坚强ぢ
    2021-01-30 10:38

    Laravel 5.2+ solution.

    Model::getQuery()->delete();
    

    Just grab underlying builder with table name and do whatever. Couldn't be any tidier than that.

    Laravel 5.6 solution

    \App\Model::query()->delete();
    

提交回复
热议问题