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: Prepopulation Trait weight: 2

The Prepopulation trait extends the functionality of a SelectFilter. Like the EnumFilter that automatically offers all cases out of an PHP Enum, this Prepopulation trait automatically loads all select options out of the database.

Given you have a field of vendor names and the name is saved in a database field named 'vendor', and you need a filter that offers all existing vendors in a select box, you can just extend your SelectFilter with the Prepopulation trait.

Usage

<?php

namespace App\Models\Filters;

use Lacodix\LaravelModelFilter\Filters\SelectFilter;
use Lacodix\LaravelModelFilter\Filters\Traits\Prepopulation;

class PrepopulatedSelectFilter extends SelectFilter
{
    use Prepopulation;
    
    protected string $field = 'vendor';
}

Options mapping

If you need to map the values, maybe because of translations, you can just add the mapOption method.

protected function mapOption(string $option): string
{
    return __('translations.' . $option);
}
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
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