Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Model Filter Laravel Package

lacodix/laravel-model-filter

Filter, search, and sort Eloquent models with reusable filter classes and query-string support. Includes built-in types (string, date, number, enum), relation/nested relation filtering, custom complex logic, and filter visualisation.

View on GitHub
Deep Wiki
Context7

title: Trashed Filter weight: 1

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".

Usage

<?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.

Visualisation and Translation

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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours