Closed promatik closed 4 months ago
Hey @promatik , from a quick look at this issue and from the description you provided, I think you are looking to know the "CrudController" stuff, mainly the routes for an entry.
I think you can foreach get_declared_classes()
and check if is_subclass_of()
the CrudController. When you have the CrudController you can match it using the model
property and then foreach the Route::getRoutes()
to check if the route you want is defined.
I am a bit concerned about making it a singleton to store dynamic stuff like the routes, because singletons in a long lived process don't get destroyed at the end of the request.
We changed CrudPanel
from singleton
to scoped
so that it behaves as a singleton only during the request lifecycle for reasons like the one I described.
I am just wondering if for example we can't just add some CrudController
method that solves this in an easier way: $this->getRegisteredRoutes()
where we appy the filtering or something similar to what I described above.
I am just not seeing the benefit apart from what I think @promatik wants to achieve and I think there is a lot to think/work to make this request viable. I will just leave some thoughts here:
ViewNamespaces::addFor('domain', 'some::namespace')
Backpack::addViewNamespaceFor('domain', 'some::namespace')
Backpack::viewNamespaces()->addFor('domain', 'some::namespace')
/***************************************************/
Route::crud()
Route::get/post (operation routes)
Backpack::addRouteFor($controller, Route::) // ??
Let's not focus on this please. Problem for future us.
I .. don't think we will ever do this.
A model can have multiple controllers, so getting the controller from the model it's a no-go IMO.
What could solve @promatik issue is having a function in the model, like getControllerClass()
that return the controller defined by the developer. He can also use session()
or some other mechanism to jiggle between controllers in case the model has more than one controller.
// in Model.php
public function getCrudController() {
if (backpack_user()->hasRole('admin') {
return AdminUserCrudController::class;
}
return UserCrudController::class;
}
I may be wrong, so if you think I am not seeing the big picture, as happened before, please re-open 🙏
Feature Request
What's the feature you think Backpack should have?
On Activity Log addon, there is a feature I would like to have, to be able to get the CrudControllers using a specific Model. @tabacitu needed something similar to this previously, and while talking we figured out it would be nice to store this info somewhere, while registering the routes for instance.
Besides the controllers, it would be nice to have much more stuff, for instance registered;
This
Backpack
singleton could include/replace the currentViewNamespaces
class.