tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.8k stars 243 forks source link

Routes Blade Directive not being recognized #115

Closed rorymcdaniel closed 6 years ago

rorymcdaniel commented 6 years ago

I'm using Laravel 5.5.28 and have tightenco/ziggy 0.6.0 installed. Console output shows that tightenco/ziggy was in fact discovered.

I've placed @routes in my base layout blade template, but it's not being rendered. Looking at the source simply shows @routes there instead of the JavaScript output I would expect.

Am I missing something obvious? What's the best way to troubleshoot this?

adilimudassir commented 6 years ago

Laravel 5.5.27 i am experiencing the same problem as well. someone should help please

ankurk91 commented 6 years ago

Does @routes() make any difference?

rorymcdaniel commented 6 years ago

No, it's the same in either case. It simply puts @routes() in the final HTML output, as if Blade isn't recognizing the directive.

rorymcdaniel commented 6 years ago

It looks like if I make a change in ZiggyServiceProvider it works. I replaced: $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { $bladeCompiler->directive('routes', function ($group) { return "<?php echo app('" . BladeRouteGenerator::class . "')->generate({$group}); ?>"; }); }); with: Blade::directive('routes', function($group = null){ return "<?php echo app('" . BladeRouteGenerator::class . "')->generate({$group}); ?>"; }); And then it works as expected. I'd be happy to do a pull request with that change if you'd like.

arturmamedov commented 6 years ago

No for me with laravel 5.4.36 this fix doesn't work. And with tightenco/ziggy v0.4.1 it work

ToujouAya commented 6 years ago

same as me it is not work in laravel 5.4.36 tightenco/ziggy 0.6.0

ankurk91 commented 6 years ago

It is working fine on:

fridzema commented 6 years ago

Not working on: PHP 7.2.1 laravel/framework 5.5.28 tightenco/ziggy 0.6.0

Displays @routes just as text.

ankurk91 commented 6 years ago

Someone can please create a repo with minimal reproduction.

fridzema commented 6 years ago

@ankurk91 I have figured out that in my case the package lab404/laravel-impersonate is the problem.

I have made a minimal reproduction https://github.com/fridzema/ziggy-issue

ankurk91 commented 6 years ago

@fridzema I was not able to re-produce the issue. What i did.

git clone https://github.com/fridzema/ziggy-issue.git
cd ziggy-issue
cp .env.example .env
php artisan key:generate
composer install
composer require lab404/laravel-impersonate
php artisan serve

The @route blade directive working fine for me (with and without laravel-impersonate package).

fridzema commented 6 years ago

@ankurk91 uuuhmm i had to do manually php artisan view:clear to see te results

ankurk91 commented 6 years ago

@fridzema Now i am able to re-produce the issue. Yes culprit is laravel-impersonate package. They seems to have fixed this issue, but no released yet. https://github.com/404labfr/laravel-impersonate/commit/ab3973b3700c1da904474248bf0737c4a22d96f2

fridzema commented 6 years ago

@ankurk91 Thanks! i'll just wait for the release.

rorymcdaniel commented 6 years ago

What is the issue with laravel-impersonate? I'm not using this package but many others. I need to know what to look for.

ankurk91 commented 6 years ago

@rorymcdaniel Check the this link. I applied that patch in current laravel-impersonate package and it worked.

ToujouAya commented 6 years ago

@ankurk91 Not working on: PHP 5.6.30 laravel/framework 5.4.36 tightenco/ziggy 0.6.0

Composer show

arcanedev/log-viewer                  4.3.1   Provides a Log Viewer for Laravel 5

arcanedev/no-captcha                  3.2.2   No CAPTCHA (new Google reCAPTCHA) with Laravel support

arcanedev/support                     3.21.4  ARCANEDEV Support Helpers

artdarek/toastr                       2.0.0   Toastr - Flash Messages for Laravel 5
barryvdh/laravel-debugbar             v2.4.3  PHP Debugbar integration for Laravel
barryvdh/laravel-dompdf               v0.7.1  A DOMPDF Wrapper for Laravel
barryvdh/laravel-ide-helper           v2.4.1  Laravel IDE Helper, generates correct PHPDocs for all Facade class...
barryvdh/reflection-docblock          v2.0.4
creativeorange/gravatar               1.0.10  A Laravel 5.0, 5.1, 5.2 and 5.3 gravatar package for retrieving gr...
davejamesmiller/laravel-breadcrumbs   3.0.3   A simple Laravel-style way to create breadcrumbs in Laravel.
dnoegel/php-xdg-base-dir              0.1     implementation of xdg base directory specification for php
doctrine/annotations                  v1.4.0  Docblock Annotations Parser
doctrine/cache                        v1.6.2  Caching library offering an object-oriented API for many cache bac...
doctrine/collections                  v1.4.0  Collections Abstraction library
doctrine/common                       v2.7.3  Common Library for Doctrine projects
doctrine/dbal                         v2.5.13 Database Abstraction Layer
doctrine/inflector                    v1.1.0  Common String Manipulations with regard to casing and singular/plu...
doctrine/instantiator                 1.0.5   A small, lightweight utility to instantiate objects in PHP without...
doctrine/lexer                        v1.0.1  Base library for a lexer that can be used in Top-Down, Recursive D...
dompdf/dompdf                         v0.7.0  DOMPDF is a CSS 2.1 compliant HTML to PDF converter
erusev/parsedown                      1.6.3   Parser for Markdown.
fzaninotto/faker                      v1.7.1  Faker is a PHP library that generates fake data for you.
guzzle/guzzle                         v3.8.1  Guzzle is a PHP HTTP client library and framework for building RES...
guzzlehttp/guzzle                     6.3.0   Guzzle is a PHP HTTP client library
guzzlehttp/promises                   v1.3.1  Guzzle promises library
guzzlehttp/psr7                       1.4.2   PSR-7 message implementation that also provides common utility met...
hamcrest/hamcrest-php                 v1.2.2  This is the PHP port of Hamcrest Matchers
hieu-le/active                        3.4.0   The helper class for Laravel (4/5) applications to get active clas...
jakub-onderka/php-console-color       0.1
jakub-onderka/php-console-highlighter v0.3.2
jeremeamia/SuperClosure               2.3.0   Serialize Closure objects, including their context and binding
laracasts/utilities                   2.1     Transform your PHP to JavaScript
laravel/browser-kit-testing           v1.0.3  Provides backwards compatibility for BrowserKit testing in Laravel...
laravel/framework                     v5.4.36 The Laravel Framework.
laravel/socialite                     v3.0.7  Laravel wrapper around OAuth 1 & OAuth 2 libraries.
laravel/tinker                        v1.0.2  Powerful REPL for the Laravel framework.
laravelcollective/html                v5.4.9  HTML and Form Builders for the Laravel Framework
league/flysystem                      1.0.41  Filesystem abstraction: Many filesystems, one API.
league/oauth1-client                  1.7.0   OAuth 1.0 Client Library
maatwebsite/excel                     2.1.22  An eloquent way of importing and exporting Excel and CSV in Larave...
mariuzzo/laravel-js-localization      v1.4.4  Laravel Localization in JavaScript
maximebf/debugbar                     1.13.1  Debug bar in the browser for php application
milon/barcode                         5.3.6   Barcode generator like Qr Code , PDF417,C39, C39+,C39E,C39E+,C93,S...
mockery/mockery                       0.9.9   Mockery is a simple yet flexible PHP mock object framework for use...
monolog/monolog                       1.23.0  Sends your logs to files, sockets, inboxes, databases and various ...
mtdowling/cron-expression             v1.2.0  CRON for PHP: Calculate the next or previous run date and determin...
myclabs/deep-copy                     1.6.1   Create deep copies (clones) of your objects
namshi/jose                           7.2.3   JSON Object Signing and Encryption library for PHP.
nesbot/carbon                         1.22.1  A simple API extension for DateTime.
nikic/php-parser                      v3.1.1  A PHP parser written in PHP
paragonie/random_compat               v2.0.10 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phenx/php-font-lib                    0.4     A library to read, parse, export and make subsets of different typ...
phenx/php-svg-lib                     0.1     A library to read, parse and export to PDF SVG files.
phpdocumentor/reflection-common       1.0.1   Common reflection classes used by phpdocumentor to reflect the cod...
phpdocumentor/reflection-docblock     3.2.2   With this component, a library can provide support for annotations...
phpdocumentor/type-resolver           0.3.0
phpoffice/phpexcel                    1.8.1   PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents ...
phpspec/prophecy                      v1.7.2  Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage             4.0.8   Library that provides collection, processing, and rendering functi...
phpunit/php-file-iterator             1.4.2   FilterIterator implementation that filters files based on a list o...
phpunit/php-text-template             1.2.1   Simple template engine.
phpunit/php-timer                     1.0.9   Utility class for timing
phpunit/php-token-stream              1.4.11  Wrapper around PHP's tokenizer extension.
phpunit/phpunit                       5.7.21  The PHP Unit Testing framework.
phpunit/phpunit-mock-objects          3.4.4   Mock Object library for PHPUnit
predis/predis                         v1.1.1  Flexible and feature-complete Redis client for PHP and HHVM
psr/http-message                      1.0.1   Common interface for HTTP messages
psr/log                               1.0.2   Common interface for logging libraries
psy/psysh                             v0.8.11 An interactive shell for modern PHP.
ramsey/uuid                           3.7.0   Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 ...
satooshi/php-coveralls                v1.0.1  PHP client library for Coveralls API
sebastian/code-unit-reverse-lookup    1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator                  1.2.4   Provides the functionality to compare PHP values for equality
sebastian/diff                        1.4.3   Diff implementation
sebastian/environment                 2.0.0   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                    2.0.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state                1.1.1   Snapshotting of global state
sebastian/object-enumerator           2.0.1   Traverses array structures and object graphs to enumerate all refe...
sebastian/recursion-context           2.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations         1.0.0   Provides a list of PHP built-in functions that operate on resources
sebastian/version                     2.0.1   Library that helps with managing the version number of Git-hosted ...
squizlabs/php_codesniffer             1.5.6   PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detect...
swiftmailer/swiftmailer               v5.4.8  Swiftmailer, free feature-rich PHP mailer
symfony/class-loader                  v3.3.9  Symfony ClassLoader Component
symfony/config                        v3.3.9  Symfony Config Component
symfony/console                       v3.3.9  Symfony Console Component
symfony/css-selector                  v3.3.9  Symfony CssSelector Component
symfony/debug                         v3.3.9  Symfony Debug Component
symfony/dom-crawler                   v3.3.9  Symfony DomCrawler Component
symfony/event-dispatcher              v3.3.9  Symfony EventDispatcher Component
symfony/filesystem                    v3.3.9  Symfony Filesystem Component
symfony/finder                        v3.3.9  Symfony Finder Component
symfony/http-foundation               v3.3.9  Symfony HttpFoundation Component
symfony/http-kernel                   v3.3.9  Symfony HttpKernel Component
symfony/polyfill-mbstring             v1.5.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php56                v1.5.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP v...
symfony/polyfill-util                 v1.5.0  Symfony utilities for portability of PHP codes
symfony/process                       v3.3.9  Symfony Process Component
symfony/routing                       v3.3.9  Symfony Routing Component
symfony/stopwatch                     v3.3.9  Symfony Stopwatch Component
symfony/translation                   v3.3.9  Symfony Translation Component
symfony/var-dumper                    v3.3.9  Symfony mechanism for exploring and dumping PHP variables
symfony/yaml                          v3.3.9  Symfony Yaml Component
tedivm/jshrink                        v1.0.1  Javascript Minifier built in PHP
tightenco/ziggy                       v0.6.0  Generates a Blade directive exporting all of your named Laravel ro...
tijsverkoyen/css-to-inline-styles     2.2.0   CssToInlineStyles is a class that enables you to convert HTML-page...
tymon/jwt-auth                        0.5.12  JSON Web Token Authentication for Laravel 4 and 5
vlucas/phpdotenv                      v2.4.0  Loads environment variables from `.env` to `getenv()`, `$_ENV` and...
webmozart/assert                      1.2.0   Assertions to validate method input/output with nice error messages.
yajra/laravel-datatables-oracle       v7.10.1 jQuery DataTables API for Laravel 4|5

image

image

gwleuverink commented 6 years ago

@ankurk91 I'm not using laravel-impersonate and also experience this issue. Currently on Laravel 5.5.26 & Ziggy 0.6.0

fridzema commented 6 years ago

What i have done to figure out which package is causing the issue is clone an empty laravel project (you can use https://github.com/fridzema/ziggy-issue) and just pasted all dependencies in composer.json. Then run composer update && php artisan view:clear if the problem persist you remove packages till you find the bottleneck (5 at a time for example) and run againcomposer update && php artisan view:clear.

Maybe not the best way but it was good enough for me to quickly find the problem.

DanielCoulbourne commented 6 years ago

@gwleuverink Can you post your composer.json?

DanielCoulbourne commented 6 years ago

We are closing this issue because it appears to be related to a package conflict.

Please update your packages and if you are able to identify other conflicting packages, point their maintainers to this thread: https://github.com/404labfr/laravel-impersonate/pull/25

jeffreyvanhees commented 6 years ago

@DanielCoulbourne No, I think it isn't a package conflict. I've got the same problem too and have no other weird packages installed. @routes is just as @routes in the HTML.

jakebathman commented 6 years ago

Can you post your composer.json file?

jeffreyvanhees commented 6 years ago

Totally stripped down my composer file and the error still exists...

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "^3.3",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.4",
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files": [
            "app/helpers.php"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover",
            "@php artisan ide-helper:generate",
            "@php artisan ide-helper:meta"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}
gwleuverink commented 6 years ago

@DanielCoulbourne Sorry for some reason missed your mention. Tough the issue is closed these were my dependencies of that point in time.

"require": {
        "php": ">=5.6.4",
        "gloudemans/shoppingcart": "^2.4",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "maatwebsite/excel": "~2.1.0",
        "pragmarx/countries": "^0.1.1",
        "santigarcor/laratrust": "5.0.*",
        "tightenco/ziggy": "^0.6.0"
},
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~6.0",
        "filp/whoops": "~2.0"
},

From the top of my head laratrust is the only package that also registers bade directives. I'll strip that out and post my findings here.

gwleuverink commented 6 years ago

I just removed all composer packages that register blade directives except Ziggy. The problem persisted still. In addition I ran composer dump-autoload & artisan view:clear just in case, but to no avail.

jeffreyvanhees commented 6 years ago

@DanielCoulbourne Please reopen this issue, it isn't 3rd party package related

jakebathman commented 6 years ago

@fancenl Your composer.json doesn't include ziggy? @gwleuverink can you post whatever you have installed after stripping everything out? We're trying to figure out under what circumstances this issue happens and then we can tackle it if needed.

(Just a note, we won't typically work on this until evenings or Fridays, but I appreciate both of you helping out 😸)

gwleuverink commented 6 years ago

Hi @jakebathman. I just updated all packages and cleared the views. Whatever the culprit was, it's fixed now.

Still peculiar that removing and reinstalling packages individually didn't work earlier today. I probably missed something.

All is working now. Thanks for the great package and the support!

kskrlin commented 6 years ago

PHP v7.1.14 ziggy v0.6.0

Same issue: @routes is rendered as string after version update. I was on v0.5.0 and there is no issue (now I am back to v0.5.0). I am not using impersonate package.

jakebathman commented 6 years ago

@kikky7 can you post your composer.json file?

kskrlin commented 6 years ago
artesaos/seotools                     v0.11.1 SEO Tools for Laravel and Lumen
barryvdh/laravel-debugbar             v3.1.0  PHP Debugbar integration for...
barryvdh/laravel-dompdf               v0.8.1  A DOMPDF Wrapper for Laravel
cocur/slugify                         v3.1    Converts a string into a slug.
cviebrock/eloquent-sluggable          4.4.1   Easy creation of slugs for y...
dimsav/laravel-translatable           v8.1    A Laravel package for multil...
dnoegel/php-xdg-base-dir              0.1     implementation of xdg base d...
doctrine/inflector                    v1.3.0  Common String Manipulations ...
doctrine/instantiator                 1.1.0   A small, lightweight utility...
doctrine/lexer                        v1.0.1  Base library for a lexer tha...
dompdf/dompdf                         v0.8.2  DOMPDF is a CSS 2.1 complian...
egulias/email-validator               2.1.3   A library for validating ema...
erusev/parsedown                      1.6.4   Parser for Markdown.
facebook/webdriver                    1.5.0   A PHP client for Selenium We...
fideloper/proxy                       3.3.4   Set trusted proxies for Laravel
filp/whoops                           2.1.14  php error handling for cool ...
fzaninotto/faker                      v1.7.1  Faker is a PHP library that ...
graham-campbell/manager               v3.0.0  Manager Provides Some Manage...
guzzlehttp/guzzle                     6.3.0   Guzzle is a PHP HTTP client ...
guzzlehttp/promises                   v1.3.1  Guzzle promises library
guzzlehttp/psr7                       1.4.2   PSR-7 message implementation...
hamcrest/hamcrest-php                 v2.0.0  This is the PHP port of Hamc...
hashids/hashids                       2.0.4   Generate short, unique, non-...
intervention/image                    2.4.1   Image handling and manipulat...
jakub-onderka/php-console-color       0.1
jakub-onderka/php-console-highlighter v0.3.2
kkszymanowski/traitor                 0.2.4   Add a trait use statement to...
laracademy/interactive-make           1.2     Interactive make CLI replace...
laravel/dusk                          v2.0.11 Laravel Dusk provides simple...
laravel/framework                     v5.5.33 The Laravel Framework.
laravel/tinker                        v1.0.3  Powerful REPL for the Larave...
laravelcollective/html                v5.5.1  HTML and Form Builders for t...
laravelnews/laravel-twbs4             1.3.1   Laravel 5 frontend preset fo...
league/flysystem                      1.0.42  Filesystem abstraction: Many...
maximebf/debugbar                     v1.14.1 Debug bar in the browser for...
mcamara/laravel-localization          v1.3.4  Easy localization for Laravel
mockery/mockery                       1.0     Mockery is a simple yet flex...
monolog/monolog                       1.23.0  Sends your logs to files, so...
mtdowling/cron-expression             v1.2.1  CRON for PHP: Calculate the ...
myclabs/deep-copy                     1.7.0   Create deep copies (clones) ...
nesbot/carbon                         1.22.1  A simple API extension for D...
nikic/php-parser                      v3.1.4  A PHP parser written in PHP
paragonie/random_compat               v2.0.11 PHP 5.x polyfill for random_...
phar-io/manifest                      1.0.1   Component for reading phar.i...
phar-io/version                       1.0.1   Library for handling version...
phenx/php-font-lib                    0.5.1   A library to read, parse, ex...
phenx/php-svg-lib                     v0.3    A library to read, parse and...
phpdocumentor/reflection-common       1.0.1   Common reflection classes us...
phpdocumentor/reflection-docblock     4.3.0   With this component, a libra...
phpdocumentor/type-resolver           0.4.0
phpspec/prophecy                      1.7.3   Highly opinionated mocking f...
phpunit/php-code-coverage             5.3.0   Library that provides collec...
phpunit/php-file-iterator             1.4.5   FilterIterator implementatio...
phpunit/php-text-template             1.2.1   Simple template engine.
phpunit/php-timer                     1.0.9   Utility class for timing
phpunit/php-token-stream              2.0.2   Wrapper around PHP's tokeniz...
phpunit/phpunit                       6.5.6   The PHP Unit Testing framework.
phpunit/phpunit-mock-objects          5.0.6   Mock Object library for PHPUnit
predis/predis                         v1.1.1  Flexible and feature-complet...
psr/container                         1.0.0   Common Container Interface (...
psr/http-message                      1.0.1   Common interface for HTTP me...
psr/log                               1.0.2   Common interface for logging...
psr/simple-cache                      1.0.0   Common interfaces for simple...
psy/psysh                             v0.8.17 An interactive shell for mod...
pusher/pusher-http-laravel            v4.0.0  A Pusher bridge for Laravel
pusher/pusher-php-server              v3.0.1  Library for interacting with...
ramsey/uuid                           3.7.3   Formerly rhumsaa/uuid. A PHP...
sabberworm/php-css-parser             8.1.0   Parser for CSS Files written...
santigarcor/laratrust                 5.0.7   This package provides a flex...
sebastian/code-unit-reverse-lookup    1.0.1   Looks up which function or m...
sebastian/comparator                  2.1.3   Provides the functionality t...
sebastian/diff                        2.0.1   Diff implementation
sebastian/environment                 3.1.0   Provides functionality to ha...
sebastian/exporter                    3.1.0   Provides the functionality t...
sebastian/global-state                2.0.0   Snapshotting of global state
sebastian/object-enumerator           3.0.3   Traverses array structures a...
sebastian/object-reflector            1.1.1   Allows reflection of object ...
sebastian/recursion-context           3.0.0   Provides functionality to re...
sebastian/resource-operations         1.0.0   Provides a list of PHP built...
sebastian/version                     2.0.1   Library that helps with mana...
stripe/stripe-php                     v5.8.0  Stripe PHP Library
swiftmailer/swiftmailer               v6.0.2  Swiftmailer, free feature-ri...
symfony/console                       v3.4.4  Symfony Console Component
symfony/css-selector                  v4.0.4  Symfony CssSelector Component
symfony/debug                         v3.4.4  Symfony Debug Component
symfony/event-dispatcher              v4.0.4  Symfony EventDispatcher Comp...
symfony/finder                        v3.4.4  Symfony Finder Component
symfony/http-foundation               v3.4.4  Symfony HttpFoundation Compo...
symfony/http-kernel                   v3.4.4  Symfony HttpKernel Component
symfony/polyfill-mbstring             v1.7.0  Symfony polyfill for the Mbs...
symfony/polyfill-php70                v1.7.0  Symfony polyfill backporting...
symfony/process                       v3.4.4  Symfony Process Component
symfony/routing                       v3.4.4  Symfony Routing Component
symfony/thanks                        v1.0.5  Give thanks (in the form of ...
symfony/translation                   v3.4.4  Symfony Translation Component
symfony/var-dumper                    v3.4.4  Symfony mechanism for explor...
theseer/tokenizer                     1.1.0   A small library for converti...
tightenco/ziggy                       v0.5.0  Generates a Blade directive ...
tijsverkoyen/css-to-inline-styles     2.2.1   CssToInlineStyles is a class...
torann/geoip                          1.0.5   Support for multiple GeoIP s...
vlucas/phpdotenv                      v2.4.0  Loads environment variables ...
webmozart/assert                      1.3.0   Assertions to validate metho...
darron1217 commented 6 years ago

I've just fixed this issue with some code modification on ServiceProvider

I modified the code below (boot method) https://github.com/tightenco/ziggy/blob/f7b0377e2a49fad84703ab03f0c3294cd6fa768f/src/ZiggyServiceProvider.php#L21-L25

into

        $this->app['blade.compiler']->directive('routes', function ($group) {
            return "<?php echo app('" . BladeRouteGenerator::class . "')->generate({$group}); ?>";
        });

I'm not sure this modification is right solution, but in my case, this helped me getting out of this strange bug. (Don't forget to run php artisan view:clear after modification)

P.S. Test environment was PHP 7.1.13 Laravel 5.5.33 Ziggy 0.6.0

jakebathman commented 6 years ago

Thanks for the help figuring this out, folks. If anyone continues having issues that might trace back to Ziggy, please open a new issue.

simonfunk commented 6 years ago

Thanks @darron1217 that works for me. Would be great if that will be implemented on next release

the94air commented 6 years ago

Well... that's a good news @darron1217. The issue toke use forever to solve. Thanks for sharing the solution with us and we will be waiting for your PR. :grinning:

darron1217 commented 6 years ago

I created PR :)

icerene commented 6 years ago

I used tightenco/ziggy 0.6.2. I replaced: $this->app['blade.compiler']->directive('routes', function ($group) { return "<?php echo app('" . BladeRouteGenerator::class . "')->generate({$group}); ?>"; }); with: \Blade::directive('routes', function($group) { return "<?php echo app('" . BladeRouteGenerator::class . "')->generate({$group}); ?>"; }); And then it works as expected.

bjmrey commented 6 years ago

For some reason I've just come across the same issue, even though I am using the latest version of the package. Laravel 5.4, PHP 7.1.5. Works in my dev environment but not in prod.

I'll look deeper into it, but in the meantime here is a quick fix: simply replace the @routes directive by <?php echo app(Tightenco\Ziggy\BladeRouteGenerator::class)->generate(); ?>

devfake commented 6 years ago

My problem was that there was a space at the end of @routes.

kriskornel commented 4 years ago

this works for me

<?php echo app(Tightenco\Ziggy\BladeRouteGenerator::class)->generate(); ?>
vinaysudani commented 4 years ago

Does @routes() make any difference?

Tried with @routes() and it worked and then switched back to @routes its still working.

selenearzola commented 4 years ago

Hello there,

I'm not able to use it on laravel 5.6 using ziggy's version 8.1. Route is not defined. Fun fact, this error only shows on my server (amazon aws ec2). Can you help me please?

wijourdil commented 3 years ago

Hello,

If you are in production, do you use cache for configuration, ... with php artisan optimize ? Maybe the solution is to run php artisan optimize:clear

I had the same issue yesterday, on my machine it worked like a charm, both on local and production env But when I deployed the code on production it did not work, the directive @routes(...) was printed directly in HTML

For me, the solution was to update my deployment script from:

...
php artisan optimize
...

to:

...
php artisan optimize:clear
php artisan optimize
...
GertjanVandenKeybus commented 10 months ago

Laravel 10. Ziggy 1.6 same issue. The fix a bit further up fixed it.

<?php echo app(Tightenco\Ziggy\BladeRouteGenerator::class)->generate(); ?>