Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for How to Extend a Filament Resource
Andréia Bohner
Andréia Bohner

Posted on

How to Extend a Filament Resource

Introduction

In this article, we'll walk through how to extend a plugin resource, as well as other Filament resources.

Checking the Plugin's Configuration

Let's say we installed a plugin that registers resources, for example, theFilament Authentication Log, and we want to extend the availableAuthenticationLogResource.php resource to add some customizations in our application.

To start with, we need to check whether the plugin enables us to configure its resources. We can take a look at theplugin's config file to see if we can locate a "resources" key or something similar that specifies the original resource(s):

// config/filament-authentication-log.php'resources'=>['AutenticationLogResource'=>\Tapp\FilamentAuthenticationLog\Resources\AuthenticationLogResource::class,],
Enter fullscreen modeExit fullscreen mode

And on theplugin's class (the class used to interact with a panel configuration file), we can check that the resources registered are the ones defined on the config file:

e.g.:/src/FilamentAuthenticationLogPlugin.php

publicfunctionregister(Panel$panel):void{$panel->resources(config('filament-authentication-log.resources'));}
Enter fullscreen modeExit fullscreen mode

Now that we have confirmed that the plugin provides this configuration, let's extend the resource!

Extending the Plugin Resource

We are ready to write our ownAuthenticationLogResource.php resource that extends the plugin's resource! We can write it in our project's Filament resource directory (app/Filament/Resources):

namespaceApp\Filament\Resources;useTapp\FilamentAuthenticationLog\Resources\AuthenticationLogResourceasBaseAuthenticationLogResource;classAuthenticationLogResourceextendsBaseAuthenticationLogResource{// your custom code here}
Enter fullscreen modeExit fullscreen mode

If you haven't yet, you can now publish the plugin's configuration file so we would be able to instruct Filament to use our custom resource. Below is an example using our localApp\Filament\Resources\AuthenticationLogResource class we've just written in the project'sconfig/filament-authentication-log.php file:

'resources'=>['AutenticationLogResource'=>\App\Filament\Resources\AuthenticationLogResource::class,],
Enter fullscreen modeExit fullscreen mode

Also, we can add the respectivecreate, edit, list, and view pages (if they are used) on our local project. Here's an example for the list page:

namespaceApp\Filament\Resources\AuthenticationLogResource\Pages;useFilament\Resources\Pages\ListRecords;classListAuthenticationLogsextendsListRecords{// ...}
Enter fullscreen modeExit fullscreen mode

There's just one more thing left: in the project's custom resource class, we need to override thegetPages() method to use our page instead of the plugin's:

useApp\Filament\Resources\AuthenticationLogResource\Pages;publicstaticfunctiongetPages():array{return['index'=>Pages\ListAuthenticationLogs::route('/'),];}
Enter fullscreen modeExit fullscreen mode

Great! Our new resource class should now be used.

This same technique can be applied to extend other Filament resources as well.

Feel free to ping me here or on mysocial networks if you have any questions, suggestions, or are using this technique. I'd love to hear from you! :)

Happy coding and see you next time!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Curious mind
  • Location
    Pale Blue Dot
  • Joined

More fromAndréia Bohner

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp