rajul
rajul
FFilament
Created by rajul on 8/19/2024 in #❓┊help
filament panel authentication middleware
I have two panels : admin and dashboard. I want to add filament panel auth middleware to certain routes . currently I am using like this :
Route::middleware(Filament::getPanel('dashboard')->getAuthGuard())->group(function () {
Route::get('/page1', function () {
return view('page');
});
});
Route::middleware(Filament::getPanel('dashboard')->getAuthGuard())->group(function () {
Route::get('/page1', function () {
return view('page');
});
});
But it is redirecting to admin login page instead of dashboard login page? Is there a way to force it to redirect to dash login in case of user is unauthenticated. Thank you!
2 replies
FFilament
Created by rajul on 4/28/2024 in #❓┊help
How to dispatch filament form data using blade $dispatch method
When I am trying to $dispatch an event to send filament form data, it is not sending updated form data. However If use dispatch inside livewire component I am able to get updated data. But by calling dispatch in livewire component will result in server call. I am trying to avoid server call. This is not send updated data:
<div>
<div class="p-4">
<form wire:submit="create">
{{ $this->form }}
<button
class="bg-gray-800 text-white rounded p-2 mt-2"
x-on:click="
$dispatch('jobsupdated', { data: {{ json_encode($this->form->getState()) }} })
"
>
Submit
</button>
</form>

</div>
</div>
<div>
<div class="p-4">
<form wire:submit="create">
{{ $this->form }}
<button
class="bg-gray-800 text-white rounded p-2 mt-2"
x-on:click="
$dispatch('jobsupdated', { data: {{ json_encode($this->form->getState()) }} })
"
>
Submit
</button>
</form>

</div>
</div>
However this is sending correct data:
public function create(): void
{
$this->dispatch('jobsupdated', data : $this->form->getState());
}
public function create(): void
{
$this->dispatch('jobsupdated', data : $this->form->getState());
}
Please let me know if there is a way to send updated form data from blade file itself to avoid server roundtrip.
4 replies
FFilament
Created by rajul on 9/9/2023 in #❓┊help
How to get active filters on table inside list resource page widget.
I am trying to get list of active filters applied on table inside a widget. My current approach is
$this->getTablePageInstance()->getTable()->getFilters()
$this->getTablePageInstance()->getTable()->getFilters()
but this is returning all filters available. How to get only active filters?
4 replies
FFilament
Created by rajul on 8/15/2023 in #❓┊help
Position of element in Dependent Select Field Option
I have a status field in a Model, where I want to show specfic set of options in Select Field based on value of status I find that position of element is not correct after selecting and updating a form. Let me explain it with example: If current status is triage and user selects 'in_progress' and save form. then Form shows the correct new options in Select (in_progress, complete, triage) but current selected option it shows is 'complete' whereas its current state is 'in_progress' Can someone please have a look at following code, If I am doing something wrong.
return $form
->schema([
Select::make('status')
->options(fn (Get $get): array => match ($get('status')) {
'triage' => [
'triage' => 'Triage',
'in_progress' => 'In Progress',
'backlog' => 'Backlog',
],
'in_progress' => [
'in_progress' => 'In Progress',
'complete' => 'Complete',
'triage' => 'Triage',
],
default => [
'triage' => 'Triage',
'in_progress' => 'In Progress',
'backlog' => 'Backlog',
],
})
]);
}
return $form
->schema([
Select::make('status')
->options(fn (Get $get): array => match ($get('status')) {
'triage' => [
'triage' => 'Triage',
'in_progress' => 'In Progress',
'backlog' => 'Backlog',
],
'in_progress' => [
'in_progress' => 'In Progress',
'complete' => 'Complete',
'triage' => 'Triage',
],
default => [
'triage' => 'Triage',
'in_progress' => 'In Progress',
'backlog' => 'Backlog',
],
})
]);
}
3 replies
FFilament
Created by rajul on 7/28/2023 in #❓┊help
slow page loading when cache is false
On a fresh laravel 10 + filament 2 , I observed a very slow loading of admin page when I set ‘cache’ => false in config/view.php I’m not sure if it’s expected behaviour or not I can file a reproduction repository of its not a expected behaviour. Thanks.
5 replies
FFilament
Created by rajul on 7/23/2023 in #❓┊help
Mutate json data in keyValue fields
Is there a way to mutate data in keyValue field of relation data,
Fieldset::make('Personal Details')
->relationship('userDetail')
->schema([
Forms\Components\KeyValue::make('meta')
->disableAddingRows()
->disableDeletingRows()
->disableEditingKeys(),
])->columns(1),
Fieldset::make('Personal Details')
->relationship('userDetail')
->schema([
Forms\Components\KeyValue::make('meta')
->disableAddingRows()
->disableDeletingRows()
->disableEditingKeys(),
])->columns(1),
I did not find any thing in $data in mutateFormDataBeforeFill
4 replies
FFilament
Created by rajul on 5/25/2023 in #❓┊help
Does afterStateHydrated called twice?
I am trying to modify a text field before filling data like this :
Fieldset::make('UUID')
->relationship('uuid')
->schema([
Forms\Components\TextInput::make('uuid')
->afterStateHydrated(function (Forms\Components\TextInput $component, $state) {
$prefix = "abc";
$component->state($prefix.$state);
})
->label('UUID')
->required()
->maxLength(255),
]),
Fieldset::make('UUID')
->relationship('uuid')
->schema([
Forms\Components\TextInput::make('uuid')
->afterStateHydrated(function (Forms\Components\TextInput $component, $state) {
$prefix = "abc";
$component->state($prefix.$state);
})
->label('UUID')
->required()
->maxLength(255),
]),
But is appending "abc" twice before $state. it is like "abcabcUUID"
2 replies
FFilament
Created by rajul on 5/12/2023 in #❓┊help
how to make filament table row clickable to model view page
I have a search Page which used filament table for user. I also have UserResource for users. How to make table row clickable to user view page.
class Search extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;
...
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->searchable()
->placeholder('-'),
Tables\Columns\TextColumn::make('contact_number')
->searchable(),
];
}

protected function getTableRecordActionUsing(): ?Closure
{
// I need help here, how to make it open ViewUser page in UserResource.
}
protected function getTableQuery(): Builder
{
return User::query()
->whereIn('pincode', $pincode_array);
}
}
class Search extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;
...
protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('name')
->searchable()
->placeholder('-'),
Tables\Columns\TextColumn::make('contact_number')
->searchable(),
];
}

protected function getTableRecordActionUsing(): ?Closure
{
// I need help here, how to make it open ViewUser page in UserResource.
}
protected function getTableQuery(): Builder
{
return User::query()
->whereIn('pincode', $pincode_array);
}
}
search.blade.php
<x-filament::page>
<form wire:submit.prevent="submit">
{{ $this->form }}
</br>
<x-filament::button type="submit">Search</x-filament::button>
</form>

<div>
{{ $this->table }}
</div>
</x-filament::page>
<x-filament::page>
<form wire:submit.prevent="submit">
{{ $this->form }}
</br>
<x-filament::button type="submit">Search</x-filament::button>
</form>

<div>
{{ $this->table }}
</div>
</x-filament::page>
4 replies
FFilament
Created by rajul on 5/7/2023 in #❓┊help
show content in table only when getTableQuery() return data
I have created a filament page and inserted a Filament form as well as a table. purpose of form is to collect user input and after user submit form, I pass those input to getTableQuery() to make a custom query, this flow works fine but by default it shows all entries in table. How can I make table to do not show content till form is submitted?
3 replies
FFilament
Created by rajul on 5/2/2023 in #❓┊help
how to refresh EditRecord Page after submit a Action::model component
I am created a entry in relation field of table by using a Action submit. It will add a new entry in reference table. How to refresh this EditRecord page so that that entry would be visible in relation-Manger tab.
2 replies
FFilament
Created by rajul on 4/28/2023 in #❓┊help
how to mutate data in record in relation in form
I have a userResource for User table which has a metadata table with its foreign-key. I have added form fields of metadata with Users fields in one form like this:
return $form
->schema([
//user table field...
...
Fieldset::make('Metadata')
->relationship('metadata')
->schema([
Forms\Components\TextInput::make('experience')
->required()
->maxLength(255),
]),
return $form
->schema([
//user table field...
...
Fieldset::make('Metadata')
->relationship('metadata')
->schema([
Forms\Components\TextInput::make('experience')
->required()
->maxLength(255),
]),
I want to mutate "experience" field of metadata before filling this form. I tried mutateRecordDataUsing, but it is not working, even dd($data) is not triggering.
->actions([
Tables\Actions\EditAction::make()->label('Edit')
->mutateRecordDataUsing(function (array $data): array {
dd($data);
}
->actions([
Tables\Actions\EditAction::make()->label('Edit')
->mutateRecordDataUsing(function (array $data): array {
dd($data);
}
How do I do this?
10 replies
FFilament
Created by rajul on 4/24/2023 in #❓┊help
In select filer 0 is giving all results
For following SelectFilter, If I select 0 then all results are coming in table , whereas 1 is working fine. Schema for verified is : $table->boolean('verified')->nullable();
SelectFilter::make('verified')
->options([
0 => 'Unverified',
1 => 'Verified',
])
->query(function (Builder $query, array $data) {
if (!empty($data['value']))
$query->whereHas('metadata',
fn(Builder $query) => $query->where('verified', '=', $data['value']));
}),
SelectFilter::make('verified')
->options([
0 => 'Unverified',
1 => 'Verified',
])
->query(function (Builder $query, array $data) {
if (!empty($data['value']))
$query->whereHas('metadata',
fn(Builder $query) => $query->where('verified', '=', $data['value']));
}),
Please let me know if I am doing something wring here?
4 replies
FFilament
Created by rajul on 4/21/2023 in #❓┊help
custom filter on foreign table not working
I have user table having gender and one foreign table with 'metadata_id" key which points to metadata. metadata contains category I created filter like this in UserResource.
SelectFilter::make('gender')->
options([
'f' => 'Female',
'm' => 'Male',
])->
attribute('gender'),
SelectFilter::make('category')
->options([
0 => 'Normal'
1 => 'Pro',
2 => 'Premium',
])
->query(function (Builder $query, array $data) {
if (!empty($data['value']))
$query->whereHas('metadata',
fn(Builder $query) => $query->where('category', '=', $data['value']));
}),
SelectFilter::make('gender')->
options([
'f' => 'Female',
'm' => 'Male',
])->
attribute('gender'),
SelectFilter::make('category')
->options([
0 => 'Normal'
1 => 'Pro',
2 => 'Premium',
])
->query(function (Builder $query, array $data) {
if (!empty($data['value']))
$query->whereHas('metadata',
fn(Builder $query) => $query->where('category', '=', $data['value']));
}),
If I select only category filter then it is working fine but If I select both gender and category filter, no users get return in table. I have confirmeed that there is data in my table to have few common users for both filters. Am I doing something wrong here?
4 replies