tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.91k stars 248 forks source link

Route::group(['name' => '']) syntax does not work #561

Closed XbNz closed 2 years ago

XbNz commented 2 years ago

Ziggy version

v1.4.6

Laravel version

v9.7.0

Description

Group routes prepended name does not apply. Tried with 'as' and 'name' array keys in route group configuration.

Ziggy call and context

Blade layout:

@routes
// ...

Vue component: 

'console.log(route('auth.login.store'))'

Error:

'Ziggy error: route 'auth.login.store' is not in the route list.'

Ziggy configuration

routes:
//...
login.create: {uri: 'login', methods: Array(2)}
login.store: {uri: 'login', methods: Array(1)}

Route definition


Route::group(['name' => 'auth.'], function () {
    Route::get('/login', [LoginController::class, 'create'])->name('login.create');
    Route::post('/login', [LoginController::class, 'store'])->name('login.store');
});
bakerkretzmar commented 2 years ago

Using as as the key, if you run php artisan route:clear and then php artisan route:list, what's the route name in the list?

bakerkretzmar commented 2 years ago

I can't reproduce this in a new app, using as it correctly prepends auth. to those route names in route:list and in Ziggy's output.

XbNz commented 2 years ago
 POST       login ........................... auth.login.store › App\Web\Authentication\Controllers\LoginController@store
 GET|HEAD   login ......................... auth.login.create › App\Web\Authentication\Controllers\LoginController@create

I wrongly assumed that name and as are synonymous. Name must be placed in the static call on the route facade. IDE confused me by presenting it as an option; it seems to do nothing when used in the group options array.

Turned out not to be a Ziggy problem. Solved.