Querying soft deleted models

With soft deletion the records are 'deleted' by defining this in a model like this:

class Model extends BaseModel
{
    protected $table = 'semesters';
    protected $primaryKey = 'id';

    use SoftDeletes;

    const CREATED_AT = 'pcdate';
    const UPDATED_AT = 'pmdate';
    const DELETED_AT = 'pddate';

So when you delete a record the 'pddate' field will be filled with the datetime at the time of deletion.

Querying soft deletions

To also get soft deleted models:

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

Only soft deleted models in your results:

$onlySoftDeleted = Model::onlyTrashed()->get();
Last update: Tue, 13 Sep 2022 14:32:15