Adam Holmes
Adam Holmes
FFilament
Created by Adam Holmes on 10/18/2024 in #❓┊help
Prepopulate constraints
When using constraints in a table filter like here: https://filamentphp.com/docs/3.x/tables/filters/query-builder is it possible to pre-populate the filters? I looked at doing it via query string, but because the constraints are dynamic it doesn't look like it'll work I have a table full of data and I'd like to "guess" which record the user wants to see by some filtering across multiple fields. I'm avoiding modifying the query of the table so that users have access to all the records. Thanks
6 replies
FFilament
Created by Adam Holmes on 10/18/2024 in #❓┊help
Actions in table column view not triggering
Hi, TLDR; Action in table ViewColumn doesn't do anything when clicked I've got a ManageRelatedRecords page - lets call it "Activity". On my activity page I have a table that displays rows of items that can be of different types. One of the columns is a ViewColumn and depending on the type, it shows different content in the view. In that view, I have an action to view more info. I've followed the docs here: https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#adding-the-action and my action appears on screen, but when I click it, nothing happens. In my table:
ViewColumn::make('description')->view('filament.tables.columns.activity-details')
ViewColumn::make('description')->view('filament.tables.columns.activity-details')
In the ManageRelatedRecords page I have my action
public function viewMoreDetailsAction(): Action
{
return Action::make('view_more_details')->action(fn() => info('Bob'));
}
public function viewMoreDetailsAction(): Action
{
return Action::make('view_more_details')->action(fn() => info('Bob'));
}
In my activity-details view I have
<div class="mt-4">
{{ $this->viewMoreDetailsAction }}
<x-filament-actions::modals />
</div>
<div class="mt-4">
{{ $this->viewMoreDetailsAction }}
<x-filament-actions::modals />
</div>
I've spent a while debugging this but I'm at a loss as to why it's not working. Any help appreciated Cheers
14 replies
FFilament
Created by Adam Holmes on 10/17/2024 in #❓┊help
Have to click action twice in component
Hi all, Strange one - I have a table with an action. The action opens up my livewire component, which just contains a table (for now). The table in the component then has it's own actions (attach) with requires confirmation set. The issue I have is that I have to click the attach action twice in order for the confirmation to appear. As you can see in the video, the loading icon spins and then it does nothing. If I click again, it works as it should. The first action looks like this:
Action::make('attach')
->label('Find')
->icon(Fa::getIcon('magnifying-glass-plus'))
->modalContent(fn(Model $record) => view('filament.components.attach-modal', ['record' => $record]))
Action::make('attach')
->label('Find')
->icon(Fa::getIcon('magnifying-glass-plus'))
->modalContent(fn(Model $record) => view('filament.components.attach-modal', ['record' => $record]))
This looks at my component view
@livewire('attach-modal', ['record' => $record])
@livewire('attach-modal', ['record' => $record])
Which loads my livewire component AttachModal where a table() method is used to generate the table with an action which is simply
Tables\Actions\Action::make('attach')
->button()
->action(function (Model $record, Action $action) {
// Do something
})
->requiresConfirmation()
Tables\Actions\Action::make('attach')
->button()
->action(function (Model $record, Action $action) {
// Do something
})
->requiresConfirmation()
and a render() method
return view('livewire.attach-modal');
return view('livewire.attach-modal');
I found I had to register the component in the AppServiceProvider too
Livewire::component('attach-modal', AttacModal::class);
Livewire::component('attach-modal', AttacModal::class);
I guess the 2 questions are: 1. Is this the correct way to add custom components to filament? 2. What's causing me having to click on the attach action twice for the confirmation to appear? Thanks!
17 replies
FFilament
Created by Adam Holmes on 10/16/2024 in #❓┊help
Modal closing on search
I have a modal which loads a component which includes a filament table. Some fields are searchable. When I type to search, the table is automatically updated ✅ However, if I type a search term and hit enter, the modal is closed ❌ I set all the following options to prove none of them are triggering it, but it still closes.
->modalSubmitAction(false)
->modalCancelAction(false)
->modalCloseButton(false)
->closeModalByClickingAway(false)
->closeModalByEscaping(false)
->modalSubmitAction(false)
->modalCancelAction(false)
->modalCloseButton(false)
->closeModalByClickingAway(false)
->closeModalByEscaping(false)
Initial findings suggest calling halt() on the action, but as it's a search field in the filament table I don't have access to it Any ideas? Thanks
6 replies
FFilament
Created by Adam Holmes on 10/11/2024 in #❓┊help
Table Column Labels
No description
5 replies
FFilament
Created by Adam Holmes on 10/7/2024 in #❓┊help
Inject other field state into viewData on ViewField
Hi, I have a field that is ToggleButtons. I then have another field which is a ViewField which I would like to regenerate depending on the option that is selected in the ToggleButtons field. At the moment, the way that I do this is to use $getRecord() in the view and then look at the value in the toggle field. The problem is that it only updates when the record is saved (as you would expect). I'd like to look at the state as is in the form before saving but I can't find a way to do this because view and viewData do not accept a closure for me to pass Get $get into it. I did attempt to find the field based on the $form using getComponent but with no luck Any ideas on a simple solution for this? Thanks
8 replies
FFilament
Created by Adam Holmes on 8/30/2024 in #❓┊help
SlideOver or EditPage
Hi all, I have the scenario where I have a resource that has an index, create and edit page. On the edit page I have a couple of relation managers. In my table on the index page I would like that when clicking the row, I go to the edit page, but when I click the EditAction then a slideOver appears (with the form). From what I've tested, it seems that slideOver only works on the action when you DON'T have an edit page. Is there a way around this? I suppose you could argue that when clicking the table row, it should go to a view page and not an edit page, but that's not what I wan't. Cheers Adam
4 replies
FFilament
Created by Adam Holmes on 8/1/2024 in #❓┊help
Table actions / alpine / livewire UI
No description
15 replies
FFilament
Created by Adam Holmes on 7/30/2024 in #❓┊help
Filament table in Modal - livewire component
Hi, this is what I'm looking to do: 1. An edit page as part of a resource - lets call that Foo ✅ 2. On that edit page, have an action in the header to select a Bar ✅ 3. When clicking that action, open a modal which has a table on it (and potentially a form at the top in future) ❌ I've done steps 1 and 2 and I've managed to get a modal to open in step 3. I've created a livewire component to display the table in the modal and a view that includes the component too. EditFoo.php
...
protected function getHeaderActions(): array
{
return [
Action::make('selectBar')
->modalHeading('Select Bar')
->modalContent(view('filament.resources.bar-resource.pages.select-bar-modal')),
];
}
...
...
protected function getHeaderActions(): array
{
return [
Action::make('selectBar')
->modalHeading('Select Bar')
->modalContent(view('filament.resources.bar-resource.pages.select-bar-modal')),
];
}
...
SelectBarModal.php
class SelectBarModal extends Component implements HasTable, HasForms
{
use InteractsWithForms;
use InteractsWithTable;

public function table(Table $table): Table
{
return $table
->query(
Bar::query()
)
->columns([
TextColumn::make('name')->label('Name'),
])
->filters([])
->actions([]);
}
}

public function render()
{
return view('filament.resources.bar-resource.pages.select-bar-modal');
}
class SelectBarModal extends Component implements HasTable, HasForms
{
use InteractsWithForms;
use InteractsWithTable;

public function table(Table $table): Table
{
return $table
->query(
Bar::query()
)
->columns([
TextColumn::make('name')->label('Name'),
])
->filters([])
->actions([]);
}
}

public function render()
{
return view('filament.resources.bar-resource.pages.select-bar-modal');
}
select-bar-modal.blade.php <x-filament::modal id="selectBarModal" width="lg" wire:model.defer="showingSelectBarModal"> <form wire:submit.prevent="selectBar"> @livewire('select-bar-modal') <x-slot name="header"> <x-filament::input type="search" wire:model="search" placeholder="Search bars..." /> </x-slot> </form> </x-filament::modal> I'm not sure if I'm missing a step or if I've added too much. I'm currently receiving the error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '1024' frame which points to Bar::query in the component class. Any thoughts would be greatly appreciated.
4 replies
FFilament
Created by Adam Holmes on 6/17/2024 in #❓┊help
Prompt input via modal on save
Hi, I have a status field on a form which is a ToggleButton populated by an enum. I would like to add some functionality so that when I save the form, if this field has changed to a specific option then a modal should appear and the user should enter a reason (which is just a text area). I would like the reason to save into a different database table as the form I'm on because I'd like to save individual rows for each change so that I can report on all the changes later (rather than overwriting the reason each time). I'm at a real loss of how to make this happen as I'm fairly new to filament. I managed to make it overwrite the data on the same model but hiding / showing a field, but that's not what I want - I want a modal to popup on save. I also tried to add a relationship to a Group but that is still a HasOne where I would like a HasMany. Any ideas or pointers in the right direction would be much appreciated. Thanks
7 replies
FFilament
Created by Adam Holmes on 5/14/2024 in #❓┊help
Testing form with relationships
Hi, I'm attempting to test a create form for my Users page. The form has basic info on, as well as a roles dropdown which uses filament-shield. When using the UI, everything works fine. When I run the test to make sure there are no errors, the test fails with the following and I can't work out why:
FAILED Tests\Feature\UserTest > `Create Page` can save form
Component has errors: "data.roles"
Failed asserting that false is true.

at vendor/livewire/livewire/src/Features/SupportValidation/TestsValidation.php:109
105▕ {
106▕ $errors = $this->errors();
107▕
108▕ if (empty($keys)) {
109▕ PHPUnit::assertTrue($errors->isEmpty(), 'Component has errors: "'.implode('", "', $errors->keys()).'"');
110▕
111▕ return $this;
112▕ }
113▕
FAILED Tests\Feature\UserTest > `Create Page` can save form
Component has errors: "data.roles"
Failed asserting that false is true.

at vendor/livewire/livewire/src/Features/SupportValidation/TestsValidation.php:109
105▕ {
106▕ $errors = $this->errors();
107▕
108▕ if (empty($keys)) {
109▕ PHPUnit::assertTrue($errors->isEmpty(), 'Component has errors: "'.implode('", "', $errors->keys()).'"');
110▕
111▕ return $this;
112▕ }
113▕
Test
test('can save form', function () {
$user = User::factory()->make();

livewire(CreateUser::class)
->fillForm($user->toArray())
->call('create')
->assertHasNoFormErrors();
});
test('can save form', function () {
$user = User::factory()->make();

livewire(CreateUser::class)
->fillForm($user->toArray())
->call('create')
->assertHasNoFormErrors();
});
Factory
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'status' => $this->faker->randomElement(UserStatus::class),
];
}
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'status' => $this->faker->randomElement(UserStatus::class),
];
}
Roles dropdown in form schema
Select::make('roles')
->relationship('roles', 'name')
->getOptionLabelFromRecordUsing(function (Model $record) {
/** @var Role $record */
return UserRole::getRoleLabel($record->name);
})
->preload()
->searchable()
->required()
->dehydrated(false),
Select::make('roles')
->relationship('roles', 'name')
->getOptionLabelFromRecordUsing(function (Model $record) {
/** @var Role $record */
return UserRole::getRoleLabel($record->name);
})
->preload()
->searchable()
->required()
->dehydrated(false),
TIA, Adam
3 replies
FFilament
Created by Adam Holmes on 5/10/2024 in #❓┊help
editOptionForm with permissions
Hi, I have a select form component which uses a relationship to look at another model. I use editOptionForm to create a modal so that I can edit the selected field. This all works fine. However, I would like the edit button to only show for certain users (which I'll manage with spatie) - but I'm not sure how to make the button show / hide? Any ideas? Thanks
3 replies
FFilament
Created by Adam Holmes on 4/26/2024 in #❓┊help
Option to set default table pagination
Hi, I'm creating some tables that have plenty data in them. I have pagination enabled with the default options of [5, 10, 25, 50, 'all'] - I'd like to keep those options, but default the view to 25 rather than 10. Looking at CanPaginateRecords I can see the below method, but it seems that we either show 10 rows if it's in the options array, otherwise we just use the first item. I could override the default options and change 10 to 9 or 11, but that doesn't feel right.
public function getDefaultPaginationPageOption(): int | string | null
{
$option = $this->evaluate($this->defaultPaginationPageOption);

if ($option) {
return $option;
}

$options = $this->getPaginationPageOptions();

if (in_array(10, $options)) {
return 10;
}

return Arr::first($options);
}
public function getDefaultPaginationPageOption(): int | string | null
{
$option = $this->evaluate($this->defaultPaginationPageOption);

if ($option) {
return $option;
}

$options = $this->getPaginationPageOptions();

if (in_array(10, $options)) {
return 10;
}

return Arr::first($options);
}
Is there a way that I can get round this? Or request it as a feature in a future release? Cheers Adam
8 replies
FFilament
Created by Adam Holmes on 4/25/2024 in #❓┊help
Writing PEST tests for Filament Tables
No description
12 replies
FFilament
Created by Adam Holmes on 4/16/2024 in #❓┊help
Query string in pagination
Hi, From an edit resource I have a button that links to another list (Audits) resource with 2 parameters like so:
Actions\Action::make(name: 'Audit Logs')
->url(function() {
return route('filament.app.resources.audit-logs.index', ['resource' => ListItemResource::getModel(), 'id' => $this->record->id]);
}),
Actions\Action::make(name: 'Audit Logs')
->url(function() {
return route('filament.app.resources.audit-logs.index', ['resource' => ListItemResource::getModel(), 'id' => $this->record->id]);
}),
In my audit list resource I then filter all the audits (this is a polymorphic table and stores the model class name and the model id - note that this is using Laravel Auditing - https://laravel-auditing.com/) based on the 2 GET parameters that are passed like so:
return $table
->modifyQueryUsing(function (Builder $query) {
$query->where('auditable_type', request()->get('resource'));
$query->where('auditable_id', request()->get('id'));
})
return $table
->modifyQueryUsing(function (Builder $query) {
$query->where('auditable_type', request()->get('resource'));
$query->where('auditable_id', request()->get('id'));
})
Which all works fine on the first load. However, when I change the pagination my request object is reset to null and therefore the above query no longer works. With Laravel you can do ::paginate()->withQueryString() but I can't find anything similar with Filament. Any ideas to ensure that the request object sticks around, or a better solution to this problem that requires no sending of things in the request? Thanks 🙂
8 replies
FFilament
Created by Adam Holmes on 4/16/2024 in #❓┊help
Unable to add form actions to modal
Hi, I've got a resource with a simple form for creating / editing. I've got a table that displays all the items on the index. Each row in the table has an edit button that opens the edit page in a modal slideover. At the bottom there is a "Save changes" and "Cancel" button. I'd like to add an additional button to the bottom, but I'm unable to get it to show. I added the below to my EditItem.php in the Resource Pages directory and the button didn't show.
protected function getFormActions(): array
{
return [
...parent::getFormActions(),
Action::make('foo')->action('bar'),
];
}
protected function getFormActions(): array
{
return [
...parent::getFormActions(),
Action::make('foo')->action('bar'),
];
}
I also tried getModalActions which made no difference. If I change the page to be a separate page rather than a modal, the button does appear - but that's not what I want. I'm at a loss, so any ideas welcome. Thanks
5 replies
FFilament
Created by Adam Holmes on 4/4/2024 in #❓┊help
Logo in Sidebar
No description
8 replies