Иногда возникает необходимость создать фильтры (выборку результатов) и отобразить их на листинге. Для таких ситуаций были созданы теги.
namespace App\MoonShine\Resources;
use App\Models\Post;
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
protected string $model = Post::class;
protected string $title = 'Posts';
public function queryTags(): array
{
return [
QueryTag::make(
'Post with author', fn(Builder $query) => $query->whereNotNull('author_id') )
];
}
}
namespace App\MoonShine\Resources;
use App\Models\Post;
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
protected string $model = Post::class;
protected string $title = 'Posts';
//...
public function queryTags(): array
{
return [
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id') // Query builder
)
];
}
//...
}
namespace App\MoonShine\Resources;
use App\Models\Post;
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
protected string $model = Post::class;
protected string $title = 'Posts';
//...
public function queryTags(): array
{
return [
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id') // Query builder
)
];
}
//...
}
namespace App\MoonShine\Resources;
use App\Models\Post;
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
protected string $model = Post::class;
protected string $title = 'Posts';
//...
public function queryTags(): array
{
return [
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id') // Query builder
)
];
}
//...
}
namespace App\MoonShine\Resources;
use App\Models\Post;
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
protected string $model = Post::class;
protected string $title = 'Posts';
//...
public function queryTags(): array
{
return [
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id') // Query builder
)
];
}
//...
}

Вы можете добавить иконку к тегу с помощью метода icon()
.
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
QueryTag::make(
'Post without an author',
fn(Builder $query) => $query->whereNull('author_id')
)
->icon('heroicons.users')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post without an author',
fn(Builder $query) => $query->whereNull('author_id')
)
->icon('heroicons.users')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post without an author',
fn(Builder $query) => $query->whereNull('author_id')
)
->icon('heroicons.users')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post without an author',
fn(Builder $query) => $query->whereNull('author_id')
)
->icon('heroicons.users')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post without an author',
fn(Builder $query) => $query->whereNull('author_id')
)
->icon('heroicons.users')
Для более подробной информации, пожалуйста, обратитесь к разделу Иконки
Вы можете сделать QueryTag активным по умолчанию. Для этого нужно использовать метод default()
.
default(Closure|bool|null $condition = null)
default(Closure|bool|null $condition = null)
default(Closure|bool|null $condition = null)
default(Closure|bool|null $condition = null)
default(Closure|bool|null $condition = null)
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
QueryTag::make(
'All posts',
fn(Builder $query) => $query
)
->default()
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'All posts',
fn(Builder $query) => $query
)
->default()
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'All posts',
fn(Builder $query) => $query
)
->default()
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'All posts',
fn(Builder $query) => $query
)
->default()
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'All posts',
fn(Builder $query) => $query
)
->default()
Вы можете захотеть отображать теги только при определенных условиях. Для этого можно использовать метод canSee()
, которому нужно передать функцию обратного вызова, возвращающую TRUE
или FALSE
.
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
QueryTag::make(
'Post with author', fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Post with author', // Заголовок тега
fn(Builder $query) => $query->whereNotNull('author_id')
)
->canSee(fn() => auth()->user()->moonshine_user_role_id === 1)
По умолчанию значение для URL генерируется автоматически из параметра label
. При этом все символы не латинского алфавита заменяются соответствующей транслитерацией 'Заголовок' => 'zagolovok'
.
Метод alias()
позволяет задать собственное значение для URL.
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
QueryTag::make(
'Archived Posts',
fn(Builder $query) => $query->where('is_archived', true)
)
->alias('archive')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Archived Posts',
fn(Builder $query) => $query->where('is_archived', true)
)
->alias('archive')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Archived Posts',
fn(Builder $query) => $query->where('is_archived', true)
)
->alias('archive')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Archived Posts',
fn(Builder $query) => $query->where('is_archived', true)
)
->alias('archive')
use Illuminate\Database\Eloquent\Builder;
use MoonShine\QueryTags\QueryTag;
//...
QueryTag::make(
'Archived Posts',
fn(Builder $query) => $query->where('is_archived', true)
)
->alias('archive')