Filters

You're browsing the documentation for an old version of MoonShine. Consider upgrading your project to MoonShine 2.x.

Filters are not much different from fields and inherit their properties and methods! They are displayed on the main page of the section to filter the list of data.

Adding new filters is easy! You can simply return all the necessary filters in the filters method which returns an array. And we will talk about filters structure in the "Filters" section.

If the method is absent or returns an empty array, then the filters will not be displayed

namespace MoonShine\Resources;
 
use MoonShine\Models\MoonshineUser;
use MoonShine\Filters\TextFilter;
 
class PostResource extends Resource
{
public static string $model = App\Models\Post::class;
 
public static string $title = 'Articles';
//...
 
 
public function filters(): array
{
return [
TextFilter::make('header', 'title')
];
}
 
// Don't forget to connect filters to the resource
public function actions(): array
{
return [
FiltersAction::make(trans('moonshine::ui.filters')),
];
}
 
 
 
//...
}