How to get all rows (soft deleted too) from a table in Laravel?

前端 未结 2 1031
盖世英雄少女心
盖世英雄少女心 2021-02-02 05:00

To get all rows from a table, I have to use Model::all() but (from good reason) this doesn\'t gives me back the soft deleted rows. Is there a way I can accomplish t

相关标签:
2条回答
  • 2021-02-02 05:26

    Use this to get all record

    Model::withTrashed()->get();
    

    Use this to get record of particular id

    Property::withTrashed()->find($list->property_id);
                  or
    

    // 1 is unique id of the table

     Model::withTrashed()->find(1);
    
    0 讨论(0)
  • 2021-02-02 05:31

    To also get soft deleted models

    $trashedAndNotTrashed = Model::withTrashed()->get();
    

    Only soft deleted models in your results

    $onlySoftDeleted = Model::onlyTrashed()->get();
    
    0 讨论(0)
提交回复
热议问题