community-forum
community-forum copied to clipboard
Route::crud - allow passing a class instead of string
@promatik mentioned it would be cool for us to be able to do:
Route::crud('products', ProductCrudController::class);
not only
Route::crud('products', 'ProductCrudController');
@karandatwani92 this is a cool little feature - you want to do it?
Hey, just my quick take on this:
Route::group(
[
'namespace' => 'Backpack\CRUD\app\Http\Controllers',
],
function () {
Route::crud('something', App\Other\MyController::class).
}
Notice the namespace configured in Route::group().
Would it become Backpack\CRUD\app\Http\Controllers\App\Other\MyController? I don't think we can ignore the namespace configuration in the route group.
Cheers
Would it become Backpack\CRUD\app\Http\Controllers\App\Other\MyController? I don't think we can ignore the namespace configuration in the route group.
Damn. Didn't think of that. Good catch, Pedro. How does Laravel do it for its own routes?
What I find intuitive... if you use ::class, that should be the full path. So it basically ignores the namespace. You either specify the full path, or import the class... which IDEs make easy. The point is that class to be clickable in the IDE, which wouldn't work if it's not the full path, or imported... What do you think?
@karandatwani92 this is a cool little feature - you want to do it?
Yes, I'll do it. Watching yours and Pedro's discussion on it, Once we reach a direction. I'll make the changes.
Turns out we had a discussion about this too - https://github.com/Laravel-Backpack/community-forum/discussions/332 🤦♂️
I tested this on the latest version, and …
(1) support for this syntax is already working fine. (2) But when I made the following default one inside(AddCustomRouteContent.php): /App/Http/Controllers/Admin/{nameTitle}CrudController::class)
One has to be manually remove namespace attribute from Route:group and append namespace to other routes for once. Then this would become compatible for future usage.
@tabacitu What should we do?
Yeah we can't really do that right now, in v5. Maaaybe we do it in v6, before the launch.
I'm pretty sure Pedro has already fixed this.