laravel-model-filter

This is the documentation for v2 but the latest version is v3 . You can switch versions in the menu at the top. Check your current version with the following command:

composer show lacodix/laravel-model-filter

Trashed Filter

Sometimes you have models that uses Laravels SoftDeletes trait. In this cases the default behaviour is showing only the models that aren't deleted, but sometimes you want to show all models including deleted or even only deleted models.

For this cases you can add the TrashedFilter to your model. The TrashedFilter is based on the SelectFilter and offers two options "with trashed" and "only trashed".

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Lacodix\LaravelModelFilter\Filters\TrashedFilter;
use Lacodix\LaravelModelFilter\Traits\HasFilters;

class Post extends Model
{
    use HasFilters;

    protected array $filters = [
        TrashedFilter::class,
    ];
}

To apply this filter use

https://.../posts?trashed_filter=with_trashed

or

Post::filter(['trashed_filter' => 'only_trashed'])->get()

The latter might be useless, since you could easily use ->onlyTrashed() directly. The benefit comes with the out of the box and ready to use select box view.

If you want configure the select options just publish views and/or language files and change the translations of the package.