2 Different Tables For The Same Resource

How can I have two different tables for the same resource with a different route for each. I want to have different fields for each and they both go to the same add/edit form?
5 Replies
jawaad
jawaad3mo ago
You can create another Resource with the same Model. Just change the $model, for example User.
php artisan make:filament-resource MyOtherUser
php artisan make:filament-resource MyOtherUser
class MyOtherUserResource extends Resource {
protected static ?string $model = User::class; // change it
// ...
}
class MyOtherUserResource extends Resource {
protected static ?string $model = User::class; // change it
// ...
}
awcodes
awcodes3mo ago
I don’t understand 2 different tables on 2 different routes can still use the same resource as long as you have 2 separate routes. It’s just that one of those those routes will have to be a custom page. Ie, you can’t have 2 different index routes and expect them to just have the same functionality. But it’s still just OOP. So just extend the default index rout and give it a different route in the resources’ get route method. What would the actual url path be that is different between the two. Maybe start there.
jawaad
jawaad3mo ago
The OP asked how to make 2 different CRUD with the same "Resource", which can be confused. Because, one CRUD = one Resource. So, my guess the OP want to have 2 different CRUD, with the same Model.
awcodes
awcodes3mo ago
I didn’t pick that up all. I read it as 2 different index routes for the same model.
rubendn
rubendnOP3mo ago
jawaad is on the right path. Let's say it's the User model. I want to have one table that shows the list of records with certain fields from the User model and another table that shows other fields from the User model but I would like the Add/Edit Form to be the same for both so if I make changes to the form, I don't have to make it in 2 places which I would have to do if I create 2 separate resources for the one model.
Want results from more Discord servers?
Add your server