question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

route().current() returning 'undefined' for form POST routes

See original GitHub issue

Hello - first off, great package, thanks so much!

I have encountered an issue where the current route value for POST routes always comes back ‘undefined’. This does not happen for my GET routes, including when I change an undefined POST route into a GET route for testing purposes. I can also change a working GET route to POST and it always returns undefined. These routes are all defined in my web.php file using the ‘web’ middleware grouping.

I also tried adding one of my POST routes to the array of excluded URIs in VerifyCsrfToken in case it was a glaring CSRF token issue, but that did not change any behavior.

Expected Behavior

route().current() should provide me with the name of my POST routes, as it does for GET routes.

Current Behavior

route().current() returns ‘undefined’ for POST routes.

For bug reports only please provide

Currently installed Laravel version:

5.4.36

Currently installed Ziggy version

0.7.1

Example route from your Laravel Routes file.

i.e. -

Route::post('studySetup', 'PathologyController@studySetup')->name('studySetup');

Contents of Ziggy.namedRoutes

assignStudies: {uri: "assignStudies", methods: Array(2), domain: null}
checkInOut: {uri: "/", methods: Array(2), domain: null}
debugbar.assets.css: {uri: "_debugbar/assets/stylesheets", methods: Array(2), domain: null}
debugbar.assets.js: {uri: "_debugbar/assets/javascript", methods: Array(2), domain: null}
debugbar.clockwork: {uri: "_debugbar/clockwork/{id}", methods: Array(2), domain: null}
debugbar.openhandler: {uri: "_debugbar/open", methods: Array(2), domain: null}
dev_connections: {uri: "dev/connections", methods: Array(2), domain: null}
downloadTables: {uri: "downloadTables", methods: Array(2), domain: null}
globalChanges: {uri: "globalChanges", methods: Array(2), domain: null}
importStudies: {uri: "importStudies", methods: Array(2), domain: null}
managePermissions: {uri: "managePermissions", methods: Array(2), domain: null}
ntpPathologistReview: {uri: "ntpPathologistReview", methods: Array(2), domain: null}
previousChanges: {uri: "previousChanges", methods: Array(2), domain: null}
qaPathologistReview: {uri: "qaPathologistReview", methods: Array(2), domain: null}
selectionCriteria: {uri: "selectionCriteria", methods: Array(1), domain: null}
standardAnimalSelection: {uri: "standardAnimalSelection", methods: Array(2), domain: null}
studySetup: {uri: "studySetup", methods: Array(1), domain: null}
updateCheckInOutData: {uri: "updateCheckInOutData/{study_number}", methods: Array(2), domain: null}
__proto__: Object

Ziggy call in context

i.e. –

$(document).ready(function() {
... 
    // Page-specific document ready functionality
    switch (route().current()) {
        case 'studySetup':
            console.log("Hooray, we made it to studySetup!");
            break;
        default:
            console.log("Not studySetup - route.current() = " + route().current());
            break;
    }
});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thdebaycommented, May 11, 2020

I’m posting this here in case it helps others - a simple trick to use the package with POST routes is to call .url() on the route object.

axios.post(route('post.store').url(), { ... })

Thanks for the great package!

1reaction
thoresuenertcommented, Jun 6, 2019

hi @kcchurch

to be clear how the current function works: It is looking for get routes only.

So when you want to check for a post route you need a second get route with the same url.

Otherwise you can fork the repo and change one specific line: https://github.com/tightenco/ziggy/blob/253b919cddc196a5a9a94c5d1e406d1b57f700f1/src/js/route.js#L123 There you see the indexOf('GET') which is your “problem”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

route().current() returning 'undefined' for form POST routes #218
I have encountered an issue where the current route value for POST routes always comes back 'undefined'. This does not happen for my...
Read more >
Model returns undefined property in post route but not get route
I finally worked it out: The res and req parameters in the get and post routes are in written in different orders. My...
Read more >
5.x API - Express.js
If a sub-app is mounted on multiple path patterns, app.mountpath returns ... Thus, the actual methods are app.get() , app.post() , app.put() ,...
Read more >
Routing - Laravel - The PHP Framework For Web Artisans
Any HTML forms pointing to POST , PUT , or DELETE routes that are defined ... If your route only needs to return...
Read more >
ActivatedRoute - Angular
An Observable that contains a map of the query parameters available to all routes. The map supports retrieving single and multiple values from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found