How do I create a custom Table Action

Hi guys, I have a resource let's title it StorefrontResource. I created a custom page based on this resource called ManageWorkers. It allows me to add members to the store. I registered the page in getPages() of the warehouse resource:
php 'manage' => Pages\ManageWorkers::route('/{record}/manage')
php 'manage' => Pages\ManageWorkers::route('/{record}/manage')
On the default list view of the StorefrontResource, how can I attach an action titled 'Manage' on the table so that when clicking it - it'll bring me to the manage workers page of the Storefront record? Storefront Resource -->Actions/ManageAction.php -->Pages/...ManageWorkers.php --StorefrontResource.php I don't want to add code in the redirect within the resource file, but rather I'd like to have a seperate action file. Is there an artisan command for creating a table action? What is the proper convention to reference the route? I'm unsure what to override in the Manage Action class. Any pointers?
<?php

namespace App\Filament\Admin\Resources\StorefrontResource\Actions;

use App\Filament\Admin\Resources\StorefrontResource;
use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Tables\Actions\Action;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Arr;

class ManageAction extends Action
{
public static function getDefaultName(): ?string
{
return 'manage';
}
}
<?php

namespace App\Filament\Admin\Resources\StorefrontResource\Actions;

use App\Filament\Admin\Resources\StorefrontResource;
use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Tables\Actions\Action;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Arr;

class ManageAction extends Action
{
public static function getDefaultName(): ?string
{
return 'manage';
}
}
Solution:
I got it working by doing this - sure it works but is this the correct way? ```php public static function make($name = 'manage'): static {...
Jump to solution
1 Reply
Solution
ashattack
ashattack13mo ago
I got it working by doing this - sure it works but is this the correct way?
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => url("/admin/storefront/{$record->getKey()}/manage"))
->label('Manage Workers');
}
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => url("/admin/storefront/{$record->getKey()}/manage"))
->label('Manage Workers');
}
Update: Minor refactor or route:
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => StorefrontResource::getUrl('manage', ['record' => $record->getKey()]))
->label('Manage Workers');
}
public static function make($name = 'manage'): static
{
return parent::make($name)
->url(fn ($record): string => StorefrontResource::getUrl('manage', ['record' => $record->getKey()]))
->label('Manage Workers');
}
Want results from more Discord servers?
Add your server