-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Allow role resource configurable #418
Allow role resource configurable #418
Conversation
PR Summary
|
You can already do what you want by publishing the resource. Otherwise publish the lang files and only keep the languages you need delete the rest. Because it's not just the title and navigation translations there are column and icon translations as well. |
@bezhanSalleh Simply, you could allow us to modify the class implementation. |
Maybe my train of thought is on a whole different space right now. So could you elaborate on what is the difference between what you are purposing and publishing the resource? |
Allowing the main class to be swapped via configuration makes it easier to extend new features without re-implementing the plugin, while maintaining flexibility for future enhancements. As you can see, most plugins allow you to swap the resource class implementation. This is because it makes our implementation more specific without needing to suggest changes to the core code. 😄 |
hmm... So you basically want to swap the role resource with your own implementation, is that what you are saying right?. you want the cli stuff but also away to use your own RoleResource instead. Now this distinction is very important because if it's just the question of overriding a couple of methods then, that would be totally different. if you are in filament discord then we can continue the discussion over there. |
@bezhanSalleh Alright. I need to change some implementations of the resource. |
to override a method let's take your example of the navigation label.
//ShieldOverrideResource.php
<?php
namespace App\Filament\Resources;
use BezhanSalleh\Shield\Resources\RoleResource;
class ShieldOverrideResource extends RoleResource
{
public static function getNavigationLabel(): string
{
return 'Roles & Permissions';
}
// this is to avoid duplication
public static function shouldRegisterNavigation(): bool
{
return true;
}
}
'shield_resource' => [
'should_register_navigation' => false,
...
use BezhanSalleh\Shield\Resources\RoleResource;
class AppServiceProvider extends ServiceProvider
{
...
public function boot()
{
$this->app->bind(RoleResource::class, \App\Filament\Resources\ShieldOverrideResource::class);
...
}
... now you can override anything your heart desires and without re-writing the whole plugin as you put it. |
@bezhanSalleh If this works, it's very good. I didn't try it before because I thought you needed to use the app() in your implementation, but I think if it's like this, it's much better. I'll try and let you know if it worked. |
@bezhanSalleh I just tested it, and this doesn't work. That's because Filament doesn't instantiate the class internally through the injection container. |
FYI, you don't have to tag me, it's my repo so i get notified anyway. It's a common way to override things in laravel so if it still doesn't work then you might have something somewhere faulty on your code base. |
Ok. Sorry to bother you, but this is very important to me. I tried doing what you said, but I didn't get any results. Can I contact you through Discord? Thank you very much! |
Sorry for bump this conversation but i have to do same thing. Did you find any solution? @a21ns1g4ts For example, I want to add it to the |
@afsakar Not really sure what you meant, but in my case, I was trying to swap out the resource class implementation, and I couldn't get it to work with bind. Honestly, I don’t know how they say it’s possible ‘cause I don’t think it is. Most Filament packages have that option in the config file, but this one doesn’t seem to. Also noticed they’re not super open to contributions. Might be better to find a more open fork, or even start our own. That’s something I’m considering too. |
Sometimes I need to change certain implementations without rewriting the entire plugin code. With this change, I'll be able to do that.
Currently, I need to modify the navigation label, but it's a translation value. To do that, I need to publish all the translation files, but I don't want to maintain this versioning in my own code. If you make this configurable, I can easily extend my own implementation.