Recently, I jumped on Laravel filament to create an admin part of an application.
Laravel filament comes with the resource that is crud ready that’s like plug and play once you set up your models.
However, depending on your customisation you might face some challenges even after going through the documentation.
Part of the task I needed to achieve was to customise the admin such that I cannot create but I can edit as well as creating a customise view.
Here is the quick solution. I will assume that you have installed larval and filament if not check here
To remove the creation part
– Delete thee Create Page File
– Remove the route from getPages() // from the resource
– Remove the CreateAction from the ListPage
The way it looks before
the button disappears
this is commented in the list eg ListMerchant etc
This is where the list is removed from the Resource eg MerchantResource.
The other part is creating a custom page
So All you have to do is to create a custom page using the following code in your home dir.
php artisan make:filament-page SortUsers --resource=UserResource --type=custom
Edit the UserResource as it is just a placeholder used above
After running the code above 2 files will be created in filament dir, one is the view class the other is the view blade page.
Go to the UserResource file and under actions add the view link we are passing
a record of the view here which will be available in the blade template
......
actions(
Tables\Actions\Action::make('view')
->url(fn (User $record): string => static::getUrl('view',['record'=> $record]))
])[
......
Also for some reason incase you are not be able to catch the record in the blade file. go the View page eg ViewUser and update like so below. so we just changing extends to ViewRecord
....
class ViewUser extends ViewRecord
{
protected static string $resource = UserResource::class;
...
After doing this once you click on the view link on the list you will redirected to a view page
You must be logged in to post a comment.