tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.86k stars 247 forks source link

@route is not recognized in app.blade.php after setting up ziggy on laravel 10 #690

Closed m-h-saeedi closed 10 months ago

m-h-saeedi commented 10 months ago

Ziggy version

1.8.1

Laravel version

10.32.0

Description

i use @route in my app.blade.php but i get this error

ReflectionException
Function () does not exist

Spatie\LaravelIgnition\Exceptions\ViewException: Function () does not exist in file /vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php on line 27

#0 /vendor/laravel/framework/src/Illuminate/Routing/RouteSignatureParameters.php(27): ReflectionFunction->__construct()
#1 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(533): Illuminate\Routing\RouteSignatureParameters::fromAction()
#2 /vendor/tightenco/ziggy/src/Ziggy.php(198): Illuminate\Routing\Route->signatureParameters()
#3 /vendor/tightenco/ziggy/src/Ziggy.php(134): Tightenco\Ziggy\Ziggy->resolveBindings()
#4 /vendor/tightenco/ziggy/src/Ziggy.php(30): Tightenco\Ziggy\Ziggy->nameKeyedRoutes()
#5 /vendor/tightenco/ziggy/src/BladeRouteGenerator.php(14): Tightenco\Ziggy\Ziggy->__construct()

i also use this and not diffrent

    @php
        echo app('Tightenco\Ziggy\BladeRouteGenerator')->generate();
    @endphp

Ziggy call and context

I use @routes in app.blade.php

Ziggy configuration

Uncaught ReferenceError: Ziggy is not defined

Route definition

Route::get('/', [HomeController::class, 'index'])->name('home');
bakerkretzmar commented 10 months ago

This looks like an issue with your route definitions, can you share the code of your HomeController::index method?

Closing because I don't think this is a bug in Ziggy but feel free to share more info here or link to a reproduction and I'm happy to help debug some more!

m-h-saeedi commented 10 months ago

just this

  public function     index()
    {
        return view('layouts.app');
    }

and in blade is

@guest
    <script>
        window.loginUrl = '{!! route('login') !!}';
    </script>

@else
     @routes
    <script>
     //some code
    </script>
@endguest

this is ok when i use v0.9.4 and when update to last version get error that mention in first

bakerkretzmar commented 10 months ago

That looks fine. The exception message looks like you might have a route missing an argument or a name or with a broken controller method. Do you have a route named login? Are you importing all your controller classes? Does this still happen after clearing your view and route cache?

m-h-saeedi commented 9 months ago

yes I have login route and imported all controller classes and clear cache and route When I use version 0.9.4, it is completely the same, but when I update to the latest version or versions one, I get this problem.

bakerkretzmar commented 9 months ago

It's one of your other routes causing an issue then. Is your app public so I can take a look? Or can you share a repo with a minimal reproduction of this issue?

m-h-saeedi commented 9 months ago

I solved the problem One of the roots had a problem Thank you for your help