Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Override Functionality #219

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

JamieCee20
Copy link
Contributor

When defining a resource in the config to extend, the form and table functions would not detect any changes.

Each page from the resource was hardcoded to take the resource class, I've changed to take the config class before defaulting back to the resource class from the package.

…se resource was hardcoded in these pages. Updated to take config, then default to the resource classes
@tharindarodrigo
Copy link
Contributor

The best way to extend is not this.
After installing the package try without registering the plugin within the AdminPanelProvider.
Create your own resources which will extend the resources within the package. This way the package resources won't appear on the panel. Instead your's will
You can override any methods within the resources

@JamieCee20
Copy link
Contributor Author

The best way to extend is not this. After installing the package try without registering the plugin within the AdminPanelProvider. Create your own resources which will extend the resources within the package. This way the package resources won't appear on the panel. Instead your's will You can override any methods within the resources

Just tried this now. It still wont work. To override the table() and form() functions, I also have to extend the pages such as ListPage and CreatePage just to change the namespace of the resource. Which could be avoided with this PR?

@JamieCee20
Copy link
Contributor Author

Other functions can be overridden fine, just not these 2 functions

@tharindarodrigo
Copy link
Contributor

Do you have a repo I can see what you have done?

@JamieCee20
Copy link
Contributor Author

JamieCee20 commented Nov 13, 2024

Sadly not as it's in a private work repo.

As best to describe it:
I made a resource locally called RoleResource, it extends the package RoleResource.
I updated the config value to change the namespace to App\Filament\Resources\RoleResource.

Then I had to create a directory RoleResource/Pages then created ListRoles.php and that extends the package page for ListRoles. So that the protected static string $resource = RoleResource::class; can have its namespace updated, as the package is hard pointing to the package RoleResource

this then allowed me to modify the public static function table() in the App\Filament\Resource\RoleResource::class to add extra fields.

@tharindarodrigo
Copy link
Contributor

After extending ListRoles of the package
Override the

static string $resource = RoleResource::class;

Property within your ListRoles class

@tharindarodrigo
Copy link
Contributor

I don't think you'll need to extend the pages at all.
I don't think there is much there in those to use except for header actions which you could add to your pages easily.

@muratkose1126
Copy link

I’m also experiencing this issue. Will this pull request be processed?

@JamieCee20
Copy link
Contributor Author

I don't think you'll need to extend the pages at all. I don't think there is much there in those to use except for header actions which you could add to your pages easily.

The thing in the page is where resource is defined. And its hard set to the package resource class. So currently I do have to extend them to replace the $resource definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants