orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
138 stars 34 forks source link

Override / extend a resource #25

Closed Ch4mpl00 closed 3 years ago

Ch4mpl00 commented 3 years ago

There are some cases when I may want to override/extend an existing resource I.e. I make some package that uses orchid crud and I want to be able to extend it from my app.

Can't figure out how to do it, can you please suggest me a solution?

tabuna commented 3 years ago

Hi. Have you tried inheriting from creating from abstract resource class?

Ch4mpl00 commented 3 years ago

Hi. Have you tried inheriting from creating from abstract resource class?

Hi! Yep I tried to make something like this: class CurrencyResource extends Resource {...} and then I added class MyCurrencyResource extends CurrencyResource {...}

It created 2 menu items: 'Currency' and 'MyCurrency' then I tried to make same label() for both classes and I got just 'Currency' in menu, so it just ignored 'MyCurrency'

tabuna commented 3 years ago

Use abstract classes. They won't be loaded abstract class CurrencyResource extends Resource

Ch4mpl00 commented 3 years ago

Yes but if I'll use abstract classes then app that uses my package will be forced to extend it. I'd like to make it optional i.e. "you can use it out of the box or extend it if you need"

It would be great to have something like symfony forms extensions

CurrencyResourceExtension extends ResourceExtension {
  public static function getExtendedTypes(): iterable
    {
        return [CurrencyResource::class];
    }
}
tabuna commented 3 years ago

If you want to have resource classes for an optional inheritance, and are not abstract and not loaded in the user interface. Then change their location. We automatically connect only those that are in the Orchid/Resources directory