Action does not open a custom modal

Hi everyone! I have a custom query defined on my List Page to group and sum inventory quantity based on locations:
namespace App\Filament\Resources\InventoryResource\Pages;

protected function getTableQuery(): Builder
{

// Return all inventories records but group by asset_id and sum the quantity
return Inventory::selectRaw('
random() as id,
asset_id,
location_id,
sum(quantity) as quantity
')
->addSelect('assets.name as asset_name')
->addSelect('locations.name as location_name')
->groupBy('asset_id', 'location_id', 'asset_name', 'location_name')
->leftJoin('assets', 'assets.id', '=', 'inventories.asset_id')
->leftJoin('locations', 'locations.id', '=', 'inventories.location_id');
//

}
namespace App\Filament\Resources\InventoryResource\Pages;

protected function getTableQuery(): Builder
{

// Return all inventories records but group by asset_id and sum the quantity
return Inventory::selectRaw('
random() as id,
asset_id,
location_id,
sum(quantity) as quantity
')
->addSelect('assets.name as asset_name')
->addSelect('locations.name as location_name')
->groupBy('asset_id', 'location_id', 'asset_name', 'location_name')
->leftJoin('assets', 'assets.id', '=', 'inventories.asset_id')
->leftJoin('locations', 'locations.id', '=', 'inventories.location_id');
//

}
I need a button on each row to display the grouped value detail records. The following code does not open a modal:
namespace App\Filament\Resources;
public static function table(Table $table): Table {
return $table
->columns([
...
])
->actions([
// Show Inventory records
Action::make('show_records')
->label(__('Show Records'))
->action(fn ($record) => $record->advance())
->modalContent(fn ($record) => view('filament.pages.actions.inventory-show-records', ['record' => $record]))
//
])
}
namespace App\Filament\Resources;
public static function table(Table $table): Table {
return $table
->columns([
...
])
->actions([
// Show Inventory records
Action::make('show_records')
->label(__('Show Records'))
->action(fn ($record) => $record->advance())
->modalContent(fn ($record) => view('filament.pages.actions.inventory-show-records', ['record' => $record]))
//
])
}
Simple blade code to test it:
<x-filament::modal>
<x-slot name="header">
Show Records
</x-slot>

<div>
{{ $this->id }}
</div>
</x-filament::modal>
<x-filament::modal>
<x-slot name="header">
Show Records
</x-slot>

<div>
{{ $this->id }}
</div>
</x-filament::modal>
Thanks in advance!
Solution:
I just resolved it. The issue was the random value used as ID
return Inventory::selectRaw('
random() as id,
return Inventory::selectRaw('
random() as id,
...
Jump to solution
9 Replies
toeknee
toeknee9mo ago
You will need requiresConfirmation() or form() I beleive to open a modal
gon.exe
gon.exe9mo ago
I tried with ->requiresConfirmation() but does not work either. I will not show a form
toeknee
toeknee9mo ago
if you remove the above, and use modalContent() with requires confirmation, does it work?
Dennis Koch
Dennis Koch9mo ago
->modalContent() should be enough I think
gon.exe
gon.exe9mo ago
->actions([
// Show Inventory records
Action::make('show_records')
->label(__('Show Records'))
->action(fn ($record) => $record->advance())
->modalContent(fn ($record) => view('filament.pages.actions.inventory-show-records', ['record' => $record]))
//

])
->actions([
// Show Inventory records
Action::make('show_records')
->label(__('Show Records'))
->action(fn ($record) => $record->advance())
->modalContent(fn ($record) => view('filament.pages.actions.inventory-show-records', ['record' => $record]))
//

])
gon.exe
gon.exe9mo ago
@Dennis Koch I am using ->modalContent() but does not work
Dennis Koch
Dennis Koch9mo ago
It's a Table Action, right? You imported the right namespace? Probably should throw an error otherwise. I don't know what's the issue then, sorry.
gon.exe
gon.exe9mo ago
I am using Filament\Tables\Actions\Action @Dennis Koch Sorry for tagging you but I just tried in another resource the same code and it works. The difference between both resources is that in the current resource where the modal does not work, I have a custom query (using getTableQuery()) on the List Page I suspect that $record->advance() doesn't work in this case
Solution
gon.exe
gon.exe9mo ago
I just resolved it. The issue was the random value used as ID
return Inventory::selectRaw('
random() as id,
return Inventory::selectRaw('
random() as id,