tomodo531/filterable-filters is a Laravel package for a laravel nova filter..
It currently has 2 GitHub stars and 1.983 downloads on Packagist (latest version 2.0.0).
Install it with composer require tomodo531/filterable-filters.
Discover more Laravel packages by tomodo531
or browse all Laravel packages to compare alternatives.
Last updated
This package can create filters based on the columns in your database. It can also filter out unused options.
composer require tomodo531/filterable-filters

namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use HasFactory;
protected $fillable = [
'title',
'content',
];
public function categories()
{
return $this->belongsToMany(Category::class, 'category_article');
}
public function author()
{
return $this->belongsTo(User::class, 'user_id');
}
}
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
Text::make('Title')
->required(),
Textarea::make('Content')
->required(),
BelongsTo::make('Author', 'author', User::class),
BelongsToMany::make('Categories'),
];
}
public function filters(NovaRequest $request)
{
return [
FilterableFilters::make(\App\Models\Article::class)
->fields([
'title', // if the field is not relational then just write the name of the database column.
'content',
'author' => [
'title' => 'name', // Works like the title in a nova resource. This is the name of the column that will be shown in the selector.
'primarykey' => 'id', // The primary key of the relational tabel. In this example the primary key of the auther or user table is 'id'.
'foreignkey' => 'user_id' // The foreign key in the nova resource model.
],
]),
];
}