You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What if we could define EVERYTHING we need to define for a CRUD, inside the CrudResource? If you prefer to define a CrudResource, I don't really see a reason why you would split your definition across multiple files:
So what if... if you're using CrudRequest... the CrudController is kind of optional? Only there in case you need to do custom stuff, add things to the setup of a particular operation or override how an operation does its thing?
How I see it implemented
To achieve that, we need to move this from the CrudController:
// BookCrudController.php
public function setup()
{
- CRUD::setModel(\App\Models\Book::class);- CRUD::setRoute(config('backpack.base.route_prefix') . '/book');- CRUD::setEntityNameStrings('book', 'books');-
$this->crudResource = new BookCrudResource();
}
But since some of the above will probably not work (see - calling the config 😅), we'll also need setters/getters for the above, so maybe:
// BookCrudResource.phpclass BookCrudResource extends CrudResource
{
protected$model = 'App\Models\Book'; // mandatoryprotected$entityNameSingular = 'book'; // optional, can figure it out from the model name tooprotected$entityNamePlural = 'books'; // optional, can figure it out from the singular too// optionalpublicfunctionmodel()
{
return \App\Models\Book::class;
}
// optional, would default to using the entity name as URL segmentpublicfunctionroute()
{
returnconfig('backpack.base.route_prefix') . '/book';
}
// optionalpublicfunctionentityNameSingular()
{
return'book';
}
// optionalpublicfunctionentityNamePlural()
{
return'books';
}
publicfunctionfields(): array
{
return [
Text::make('Name')->size(9),
Number::make('Year')->size(3),
Textarea::make('Description')->onlyOnForms(),
Text::make('ISBN'),
];
}
}
What I've already tried to fix it
Nothing, just spitballing.
Would I be able to work on this myself and submit a PR
Sure, before we launch v6.
The text was updated successfully, but these errors were encountered:
Feature Request
What I am trying to achieve
What if we could define EVERYTHING we need to define for a CRUD, inside the CrudResource? If you prefer to define a CrudResource, I don't really see a reason why you would split your definition across multiple files:
So what if... if you're using CrudRequest... the CrudController is kind of optional? Only there in case you need to do custom stuff, add things to the setup of a particular operation or override how an operation does its thing?
How I see it implemented
To achieve that, we need to move this from the CrudController:
to the CrudResource:
But since some of the above will probably not work (see - calling the config 😅), we'll also need setters/getters for the above, so maybe:
What I've already tried to fix it
Nothing, just spitballing.
Would I be able to work on this myself and submit a PR
Sure, before we launch v6.
The text was updated successfully, but these errors were encountered: