Sesh
Sesh
FFilament
Created by Sesh on 9/22/2023 in #❓┊help
How to stop an action on certain conditions with ->before()
What is the best practice in Filament to stop an action from continuing before it runs into a exception? For example I want to show a message to the user if delete is not possible because the category is used for items:
DeleteAction::make('delete')
->before(function (TrendRadarTrendSegment $record) {
if ($record->radarTrends()->count() > 0) {
Notification::make()
->title('Delete failed')
->body(__('This segment is used by trends and cannot be deleted. Please move the trends to another segment first.'))
->danger()
->send();
}
})
DeleteAction::make('delete')
->before(function (TrendRadarTrendSegment $record) {
if ($record->radarTrends()->count() > 0) {
Notification::make()
->title('Delete failed')
->body(__('This segment is used by trends and cannot be deleted. Please move the trends to another segment first.'))
->danger()
->send();
}
})
How can I break out of the DeleteAction in this case? Or is there another way to catch en exception and show a notification?
5 replies
FFilament
Created by Sesh on 8/23/2023 in #❓┊help
Change a table filter from an updated lifecycle hook
I need to change table filter of a V3 standalone table component from a livewire updated lifecycle hook. Basically my questions is: How can I change and apply the table filter from the updated() function outside of the table function.
3 replies
FFilament
Created by Sesh on 8/14/2023 in #❓┊help
How to search in multiple fields in v3 SelectFilter?
I am using the following relationship select filter:
SelectFilter::make('players')
->label(__('Players'))
->relationship('players', 'name_en')
->searchable()
->multiple()
SelectFilter::make('players')
->label(__('Players'))
->relationship('players', 'name_en')
->searchable()
->multiple()
When I enter a search query in the select filter it should not only find results with a match on "name_en" but also on "shortname_en". What I tried: - Add an array of searchable columns to ->searchable(['name_en','shortname_en']) as it would work in the form select => Did not work - Use a virtual column => Did not work properly because there is not always a value in shortname_en (its nullable) so the virtual is empty in this case - Using a custom attribute on the model => Didn't work as Filters are doing a direct sql query Anybody has an idea how to make the Filter search also search in "shortname_en"?
3 replies
FFilament
Created by Sesh on 8/12/2023 in #❓┊help
How to make the current page indicator more visible in v3 table pagination?
3 replies
FFilament
Created by Sesh on 8/11/2023 in #❓┊help
Customize / translate CreateAction modal title
9 replies
FFilament
Created by Sesh on 8/9/2023 in #❓┊help
Delete action in table builder V3 seems to ignore Policy
I set up a Edit and a Delete action in the V3 table builder. Both policies work correctly when I check them in tinker (so the policy is correctly registered) but in the table builder action the delete action does delete the record and ignores the policy. Am I am missing something? Or is the standalone table builder not behaving the same as the panel: https://filamentphp.com/docs/3.x/panels/resources/deleting-records#authorization in observing model policies?
3 replies
FFilament
Created by Sesh on 8/9/2023 in #❓┊help
Select filter grouping options in relation filter
I am struggling to get a Select filter on a relation working with option groups described here: https://filamentphp.com/docs/3.x/forms/fields/select#grouping-options This is my Select field in the table filters:
SelectFilter::make('trends')
->label(__('Trends'))
->searchable()
->options($formattedData)
->preload(),
SelectFilter::make('trends')
->label(__('Trends'))
->searchable()
->options($formattedData)
->preload(),
The format of the options is right and they get displayed correctly with the groups, butwhen i select an entry, I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'trends' in 'where clause'
SELECT
count(*) AS aggregate
FROM
`news`
WHERE
(`trends` = 1)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'trends' in 'where clause'
SELECT
count(*) AS aggregate
FROM
`news`
WHERE
(`trends` = 1)
How can I configure the select so its checking the relation. When I use ->relation() it takes the options from the relation and not from the customized option array. Thanks.
9 replies
FFilament
Created by Sesh on 8/3/2023 in #❓┊help
How to use deep relations in filters in the V3 Table Builder?
Is there a way to use deep relations in filters in V3? I have the following relation: News => belongsToMany => players => belongsTo => playerCategory Which is defined in the News Model like this (and works):
public function playerCategories()
{
return $this->hasManyDeepFromRelations($this->players(), (new Player())->playerCategory());
}
public function playerCategories()
{
return $this->hasManyDeepFromRelations($this->players(), (new Player())->playerCategory());
}
I want to add a Filter for playerCategories in the News table builder component. I tried this:
SelectFilter::make('playerCategories')
->label(__('Player Categories'))
->preload()
->relationship(playerCategories', 'name_en')
->multiple(),
SelectFilter::make('playerCategories')
->label(__('Player Categories'))
->preload()
->relationship(playerCategories', 'name_en')
->multiple(),
And got this error:
Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Staudenmeir\EloquentHasManyDeep\HasManyDeep returned
Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Staudenmeir\EloquentHasManyDeep\HasManyDeep returned
Does anyone know how to achieve this? Thanks 🙏
5 replies
FFilament
Created by Sesh on 8/2/2023 in #❓┊help
Active filter badges are repeating themselves
4 replies
FFilament
Created by Sesh on 8/2/2023 in #❓┊help
How to "Should select current page only" in V3?
I couldn't find the method to only allow to select the current page and not all in the new table builder for bulk actions. In v2 it was:
protected function getShouldSelectCurrentPageOnly(): bool
{
return false;
}
protected function getShouldSelectCurrentPageOnly(): bool
{
return false;
}
Does someone know? Thanks.
5 replies
FFilament
Created by Sesh on 8/2/2023 in #❓┊help
Arranging records into a grid does not work
I just tried to arrange my table content into a grid as described here: https://filamentphp.com/docs/3.x/tables/layout#arranging-records-into-a-grid. But it does not work (content is still in the table form). Am I missing something or is the functionality not yet implemented in v3? Here is my code:
return $table
->query(Study::query())
->columns([
TextColumn::make('access')
->badge()
->label(__('Access'))
->colors([
'primary'
])
->sortable(),
TextColumn::make('date')
->label(__('Date'))
->date()
->extraAttributes(['class' => 'text-sm mt-2'])
->sortable(),
TextColumn::make('title')
->label(__('Title'))
->extraAttributes(['class' => 'text-xl font-bold mt-1'])
->searchable()
->sortable(),
])
->defaultSort('date', 'desc')
->persistSortInSession()
->filters([
// ...
])
->persistFiltersInSession()
->actions([
// ...
])
->bulkActions([
// ...
])
->paginated([12, 24, 48, 96, 'all'])
->recordUrl(
fn (Model $record): string => route('studies.show', $record->id)
)
->contentGrid([
'md' => 2,
'xl' => 3,
]);
return $table
->query(Study::query())
->columns([
TextColumn::make('access')
->badge()
->label(__('Access'))
->colors([
'primary'
])
->sortable(),
TextColumn::make('date')
->label(__('Date'))
->date()
->extraAttributes(['class' => 'text-sm mt-2'])
->sortable(),
TextColumn::make('title')
->label(__('Title'))
->extraAttributes(['class' => 'text-xl font-bold mt-1'])
->searchable()
->sortable(),
])
->defaultSort('date', 'desc')
->persistSortInSession()
->filters([
// ...
])
->persistFiltersInSession()
->actions([
// ...
])
->bulkActions([
// ...
])
->paginated([12, 24, 48, 96, 'all'])
->recordUrl(
fn (Model $record): string => route('studies.show', $record->id)
)
->contentGrid([
'md' => 2,
'xl' => 3,
]);
8 replies
FFilament
Created by Sesh on 8/2/2023 in #❓┊help
Show table in grid
How can I show a table in a grid in V3? In V2 it was possible with like this: https://filamentphp.com/docs/2.x/tables/layout#arranging-records-into-a-grid I did not find it in the documentation for v3.
7 replies
FFilament
Created by Sesh on 7/29/2023 in #❓┊help
How to disable select all in Table Builder?
I found a method to disable "Select all" for bulk actions in the admin panel: protected bool $shouldSelectCurrentPageOnly = true; How can I use this function in the table builder?
7 replies
FFilament
Created by Sesh on 7/29/2023 in #❓┊help
Certain font sizes (e.g. xs, xl) do not work in Table Builder
I would like to use the tailwind font sizes "xs" and "xl" in the table builder for a TextColumn e.g. like this:
Tables\Columns\TextColumn::make('date')
->date()
->sortable()
->size('xs'),
Tables\Columns\TextColumn::make('date')
->date()
->sortable()
->size('xs'),
"sm" and "lg" works fine. What am I doing wrong? They are used elsewhere in the app so they should be part of the css.
5 replies
FFilament
Created by Sesh on 7/27/2023 in #❓┊help
How to change style of card when arranged to grid?
11 replies
FFilament
Created by Sesh on 4/21/2023 in #❓┊help
How to force users to re-login when accessing Filament (used as backend)?
I am using Filament as a backend for admins on an app with a TALL frontend (with Laravel Auth Login for the clients). The Filament login backend is also proteced by two-factor (through the filament 2FA plugin). There is just one user model and admins also have access to the frontend where they can login without 2FA (I do not want to force clients to use 2FA). At the moment an admin can circumvent 2FA by logging into the frontend and then accessing the Filament backend. I want users accessing the backend to be forced to login with 2FA through the Filament login flow. How can I achieve that?
2 replies