namespace App\MoonShine\Resources;
use Illuminate\Database\Eloquent\Builder;
use MoonShine\Laravel\QueryTags\QueryTag;
use MoonShine\Laravel\Resources\ModelResource;
class PostResource extends ModelResource
{
// ...
protected function queryTags(): array
{
return [
QueryTag::make(
'Post with author', // Tag title
fn(Builder $query) => $query->whereNotNull('author_id') // Query builder
)
];
}
}
use Illuminate\Database\Eloquent\Builder;
use MoonShine\Laravel\QueryTags\QueryTag;
QueryTag::make(
'Post without an author',
fn(Builder $query) => $query->whereNull('author_id')
)
->icon('users')
For more detailed information, please refer to the section Icons.
You might want to display tags only under certain conditions.
You can use the canSee() method, which requires you to pass a callback function that returns TRUE or FALSE.
// torchlight! {"summaryCollapsedIndicator": "namespaces"}
// [tl! collapse:2]
use Illuminate\Database\Eloquent\Builder;
use MoonShine\Laravel\QueryTags\QueryTag;
QueryTag::make(
'Post with author', // Tag title
fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
use Illuminate\Database\Eloquent\Builder;
use MoonShine\Laravel\QueryTags\QueryTag;
QueryTag::make(
'Post with author', // Tag title
fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
By default, the URL value is automatically generated from the label parameter.
All non-Latin alphabet characters are replaced with their corresponding transliteration, e.g., 'Заголовок' => 'zagolovok'.
The alias() method allows you to set a custom value for the URL.
By default, all tag buttons are displayed in a line, but you can display them through a drop-down list.
To do this, change the $queryTagsInDropdown property in the resource.