tighten / ziggy

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

Combination of old and new route definition syntax in same app breaks ziggy. #629

Closed Sjos12 closed 1 year ago

Sjos12 commented 1 year ago

Ziggy version

v1.5.0

Laravel version

v9.0

Description

We are working on a large scale application that has recently upgraded to Laravel 8.0. The application makes use of both the old (string) and new (array) syntax in different parts in the app for defining routes.

new Route::get('/example', [ExampleController::class, 'exampleMethod']);

and

old Route::get('/example', 'ExampleController@exampleMethod');

However Ziggy doesn't seem to support using both the old and the new syntax at the same time. Only allowing the old syntax where a route is defined via a string. The following error is thrown while generating the route file for the new syntax:


[2023-04-14 09:54:03] local.ERROR: ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given (View: /var/www/dossierdata/resources/views/index.blade.php) (View: /var/www/dossierdata/resources/views/index.blade.php) {"userId":2,"exception":"[object] (Illuminate\\View\\ViewException(code: 0): ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given (View: /var/www/dossierdata/resources/views/index.blade.php) (View: /var/www/dossierdata/resources/views/index.blade.php) at /var/www/dossierdata/vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php:27)
[stacktrace]

To try and workaround this issue I thought I might define a filter array under config/ziggy.php to only allow generation for route definitions using the old syntax. But after looking at the Ziggy source code it seems that ziggy is still retrieving and processing routes that are excluded under config/ziggy.php.

Any help is much appreciated.

Ziggy call and context

I installed Ziggy as described in the documentation. I'm using Ziggy by adding the @routes directive to our head tag in index.blade.php. The error is thrown after I add the @routes directive and try to visit the website.

Ziggy configuration

A Ziggy object hasn't been generated yet because the error is being thrown during the build process.

Route definition

Route::get('/example', [ExampleController::class, 'exampleMethod']);
bakerkretzmar commented 1 year ago

Can you share the full stack trace and a more complete example route definition? E.g. if you're importing the controller class or adding any middleware to the route. It doesn't look like that error is coming from your routes file.

bakerkretzmar commented 1 year ago

This doesn't look related to Ziggy. Feel free to comment again if you can share more information or reproduce this in a fresh app.