laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Proposal] Uniforms "Route Name Prefixes" attributes name #1521

Open wgh000 opened 5 years ago

wgh000 commented 5 years ago

Documentation suggest to use function name() in order to prefix routes names:

Route::name('admin.')->group(function () {
    Route::get('users', function () {
        // Route assigned name "admin.users"...
    })->name('users');
});

But, writing a custom entry in RouteServiceProvider.php requires to use the as parameter and that's not so clear.

/**
 * Define the "ajax" routes for the application.
 *
 * These routes all receive session state, CSRF protection, etc.
 *
 * @return void
 */
protected function mapAjaxRoutes()
{
    Route::group([
        'middleware' => 'web',
        'namespace' => $this->namespace . '\Ajax',
        'prefix' => 'ajax',
        'as' => 'ajax.', // here is the right parameter
        // 'name' => 'ajax.', // this is not working
    ], function ($router) {
        require base_path('routes/ajax.php');
    });
}

What I propose is a quick fix in order to start uniforming variables names.

Please check changes proposed: https://github.com/wgh000/framework/commit/a1c4bedc91e97a9ea631af179e9318686899f303

ankurk91 commented 5 years ago

Groups has prefix and Individual routes has names. I dont think that group should have a name.

wgh000 commented 5 years ago

Yes, groups have prefix (URL prefix), but as per documentation (https://laravel.com/docs/master/routing#route-group-name-prefixes) there is also name prefix: the fact that prefix is called name and it differs from the internal code, is not a great help.

I think the naming should be unified.

Route Name Prefixes

Route::name('admin.')->group(function () {
    Route::get('users', function () {
        // Route assigned name "admin.users"...
    })->name('users');
});

In this example, route can be called using route('admin.users') but doesn't mean that will correspond to a /admin/users URI

ankurk91 commented 5 years ago

I agree with OP. The naming can be improved.