Eugen Pașca
Eugen Pașca
FFilament
Created by Eugen Pașca on 4/24/2024 in #❓┊help
Resource Page navigation items with Proper Policies
Hello, I am looking into improving the navigation on an application build with Filament. I know this was discussed before, but my flavor of issue includes the policies. Here is my Panel provider, navigationItems part
->navigationGroups([
NavigationGroup::make()->label('GDPR'),
])
->navigationItems([
NavigationItem::make('Sign')
->url(fn() => GdprRequestResource::getUrl('create'))
->isActiveWhen(fn() => request()->routeIs(
GdprRequestResource\Pages\CreateGdprRequest::getRouteName('dashboard')
))
->group('GDPR')
->sort(1)
->visible(fn() => auth()->user()->can('create', GdprRequest::class)),
NavigationItem::make('View all')
->url(fn() => GdprRequestResource::getUrl('index'))
->isActiveWhen(fn() => request()->routeIs(
GdprRequestResource\Pages\ListGdprRequests::getRouteName('dashboard'),
GdprRequestResource\Pages\ViewGdprRequest::getRouteName('dashboard'),
))
->group('GDPR')
->sort(2)
->visible(fn() => auth()->user()->can('viewAny', GdprRequest::class)),
])
->navigationGroups([
NavigationGroup::make()->label('GDPR'),
])
->navigationItems([
NavigationItem::make('Sign')
->url(fn() => GdprRequestResource::getUrl('create'))
->isActiveWhen(fn() => request()->routeIs(
GdprRequestResource\Pages\CreateGdprRequest::getRouteName('dashboard')
))
->group('GDPR')
->sort(1)
->visible(fn() => auth()->user()->can('create', GdprRequest::class)),
NavigationItem::make('View all')
->url(fn() => GdprRequestResource::getUrl('index'))
->isActiveWhen(fn() => request()->routeIs(
GdprRequestResource\Pages\ListGdprRequests::getRouteName('dashboard'),
GdprRequestResource\Pages\ViewGdprRequest::getRouteName('dashboard'),
))
->group('GDPR')
->sort(2)
->visible(fn() => auth()->user()->can('viewAny', GdprRequest::class)),
])
The idea is to have in the navigation a group, in this example is called GDPR and in that group at least 2 items. for this nav group: Sign and View all. - Problem 1: I cannot find a better way to include the CREATE page into navigation other then a custom nav item - Problem 2: If i add the create page into the navigation and assign the isActivWhen as in example, the default ResourceList nav is active when the create is active so i need to use a custom nav item for this also - Problem 3. Now that i use custom nav items i lost the default Policy check and have to use the visible method Everything works as expected but i don`t feel this this is the best version. What happens when i add additional pages to that resource, have to update the isActiveWhen also. Does anybody have a better implementation for this?
2 replies
FFilament
Created by Eugen Pașca on 4/4/2024 in #❓┊help
SelectFilter search in multiple columns - Is this intended
Hello, I am working on a resource where i am looking into filtering and i found out that a SelectFilter can't searech in multiple columns. The clasic User having first_name and last_name Is this an intended functionality? As seen bellow, i replicated that functionality using a Filter with a Select inside but it looks like too much trouble for just a simple search in multiple columns Am i thinking of this the wrong way? Should we improve on the filter? What you thing?
Filter::make('custom_creator_id')
->form([
Select::make('creator_id')
->label('Agent 22')
->searchable(['first_name', 'last_name'])
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
])
->query(fn(Builder $query, array $data): Builder => $query
->when(
$data['creator_id'],
fn(Builder $query, $creatorId): Builder => $query->where('creator_id', $creatorId),
)),

SelectFilter::make('creator_id')
->label('Agent')
->searchable() // Here accept only a boolean or a Closure - the closure should return a boolean
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
Filter::make('custom_creator_id')
->form([
Select::make('creator_id')
->label('Agent 22')
->searchable(['first_name', 'last_name'])
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
])
->query(fn(Builder $query, array $data): Builder => $query
->when(
$data['creator_id'],
fn(Builder $query, $creatorId): Builder => $query->where('creator_id', $creatorId),
)),

SelectFilter::make('creator_id')
->label('Agent')
->searchable() // Here accept only a boolean or a Closure - the closure should return a boolean
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
5 replies
FFilament
Created by Eugen Pașca on 1/25/2024 in #❓┊help
Error on the hidden method on Action (Typed property ...Component::$container)
Hello, I am having some issues with an action that i have places inside a form:
Section::make(__('app..description'))
->schema([

TableRepeater::make('name')
->label('label')
->relationship('relationship')
->schema([

TextInput::make('product'),
TextInput::make('company_id'),
TextInput::make('quantity'),
TextInput::make('price'),

Actions::make([
Actions\Action::make('action_name')
->label(__('app.label'))
->requiresConfirmation()
->color('danger')
->tooltip(__('app._tooltip'))
->iconButton()
->icon('heroicon-o-x-circle')
->action(function (ClusterOrderItemAssignment $item) {
//...
})
->hidden(function (?Model $record) {
return $record->some_bool_attribute;
}),
]),
])
->hideLabels()
->columnSpanFull(),
]);
Section::make(__('app..description'))
->schema([

TableRepeater::make('name')
->label('label')
->relationship('relationship')
->schema([

TextInput::make('product'),
TextInput::make('company_id'),
TextInput::make('quantity'),
TextInput::make('price'),

Actions::make([
Actions\Action::make('action_name')
->label(__('app.label'))
->requiresConfirmation()
->color('danger')
->tooltip(__('app._tooltip'))
->iconButton()
->icon('heroicon-o-x-circle')
->action(function (ClusterOrderItemAssignment $item) {
//...
})
->hidden(function (?Model $record) {
return $record->some_bool_attribute;
}),
]),
])
->hideLabels()
->columnSpanFull(),
]);
From my tests, when i add the hidden method and add a Model property to the callback i get this error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization Any idea why? it works on other fields, only on action I get this error. As for versions: - PHP 8.2.11 - Laravel: 10.41.0 - Filament: 3.0.12
2 replies
FFilament
Created by Eugen Pașca on 9/20/2023 in #❓┊help
List Resources - GetTabs: modifyQueryUsing not working with relationships or scopes
No description
8 replies