F
Filamentβ€’2y ago
Jamie Cee

Little lost on generating resource from a vendor model

php artisan make:filament-resource Customer --generate
php artisan make:filament-resource Customer --generate
So the command above would generate a resource from the Customer model, but what if the model was inside a vendor package?
19 Replies
Bruno Pereira
Bruno Pereiraβ€’2y ago
I would create a model and extend the one on vendor folder. Then the resource would be linked to the one I created
Jamie Cee
Jamie CeeOPβ€’2y ago
Yeah that works, but also isn't efficient in the case I am after, as it would mean extending every model we have in packages to then generate resources, if you know what I mean?
Bruno Pereira
Bruno Pereiraβ€’2y ago
Yeah I see, I think there's a property in the resource to tell which model to use. Let me check
Jamie Cee
Jamie CeeOPβ€’2y ago
Yeah cool, I just couldnt find anything in the documentation so not sure im looking in the right place
Bruno Pereira
Bruno Pereiraβ€’2y ago
protected static ?string $model = null; You put that on the resource you created and link it to the model you want
Jamie Cee
Jamie CeeOPβ€’2y ago
So I cant use the --generate command to get all my table and form info from the model filalbles
Bruno Pereira
Bruno Pereiraβ€’2y ago
If theres a param on the command to select the model you can, otherwise I think not
Jamie Cee
Jamie CeeOPβ€’2y ago
Darn
Bruno Pereira
Bruno Pereiraβ€’2y ago
If you have the time or know how maybe it's a nice feature for a PR
Jamie Cee
Jamie CeeOPβ€’2y ago
I would like to think so, but im not smart enough for that 🀣
Bruno Pereira
Bruno Pereiraβ€’2y ago
Ahaha same
awcodes
awcodesβ€’2y ago
Did you try name spacing the model with the generate command? Something like Package\\Models\\Model
Jamie Cee
Jamie CeeOPβ€’2y ago
I didnt try with double \, Ill give that a go Nah, that still hasn't picked up my Profile Model. php artisan make:filament-resource \Arch\User\Models\Profile --generate It's looking like this: use App\Models\Arch\User\Models\Profile;
awcodes
awcodesβ€’2y ago
yea, looking at the code. it doesn't look possible to do this in this way. For now, i would do as others said and extend the package model for the generate command, then you can just delete the local model and update it's references in the Resources after it's generated. I know it's not optimal, but would still be quicker that building them by hand.
Jamie Cee
Jamie CeeOPβ€’2y ago
Think Im closing in on working it in the code at the moment, if I can get it to something alright, Ill submit it as a PR, just im a junior dev so dont wanna contribute when it could be done better
awcodes
awcodesβ€’2y ago
don't worry about being a Jr. πŸ™‚ that's just a title assigned to you by a company.
Jamie Cee
Jamie CeeOPβ€’2y ago
Is also very much my skill level 🀣 Just working around with policies now, as my Profile model that I am using has a policy but doesn't return booleans (which I think may just be bad practice on my end) I made a PR but since it was a small change, it may be easier to just flag it as a feature request, as it works locally but not sure if it's gonna be needed else where, as I've only used it in my use case
awcodes
awcodesβ€’2y ago
I think a PR is good because it offers the ability for other non filament packages.
Jamie Cee
Jamie CeeOPβ€’2y ago
Cool, well thats submitted πŸ™‚

Did you find this page helpful?