The closest there is in laravel is resource routes. https://laravel.com/docs/9.x/controllers#resource-controllers
Default named routes relating to the route url (Laravel 9)
I was wondering if there was some default functionality in the laravel routes file (web.php or any other route file) where you could do the following:-
Route::get('pages/books/categories', 'App\Http\Controllers\Page\Book\PageBookCategoryController@index');
And named route for the above would be 'pages/books/categories'?
At the moment I am having to do the following for it to work as expected:-
Route::get('pages/books/categories', 'App\Http\Controllers\Page\Book\PageBookCategoryController@index') ->name('pages/books/categories');
Of course this gives me the named route as 'pages/books/categories'.
The only reason why I want to do the above is because I have quite a few routes and it's quite tedious to add a named route if the url for the route is exactly the same.
Here's a line you could take for a walk...
// RouteServiceProvider
public function boot()
{
\Illuminate\Routing\Route::macro('defaultName', function () {
$this->name($this->uri);
});
// ...
// routes/web.php
Route::get('pages/books/categories', 'App\Http\Controllers\Page\Book\PageBookCategoryController@index')
->defaultName();
The implementation of the macro is optimistic; I will guarantee there will be edge cases where it will need tweaking, but it could get you started...
Please or to participate in this conversation.