community-forum icon indicating copy to clipboard operation
community-forum copied to clipboard

Route::crud - allow passing a class instead of string

Open tabacitu opened this issue 2 years ago • 7 comments

@promatik mentioned it would be cool for us to be able to do:

Route::crud('products', ProductCrudController::class);

not only

Route::crud('products', 'ProductCrudController');

tabacitu avatar Nov 15 '22 18:11 tabacitu

@karandatwani92 this is a cool little feature - you want to do it?

tabacitu avatar Dec 13 '22 11:12 tabacitu

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

pxpm avatar Dec 13 '22 13:12 pxpm

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?

tabacitu avatar Dec 13 '22 13:12 tabacitu

@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.

karandatwani92 avatar Dec 14 '22 05:12 karandatwani92

Turns out we had a discussion about this too - https://github.com/Laravel-Backpack/community-forum/discussions/332 🤦‍♂️

tabacitu avatar Dec 27 '22 06:12 tabacitu

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?

karandatwani92 avatar Feb 11 '23 15:02 karandatwani92

Yeah we can't really do that right now, in v5. Maaaybe we do it in v6, before the launch.

tabacitu avatar Feb 16 '23 16:02 tabacitu

I'm pretty sure Pedro has already fixed this.

tabacitu avatar Aug 22 '24 12:08 tabacitu