ziggy: Don't check domain value at route().current()

Description

I’m developing a Laravel 8 project locally and can access it via both (and many more) localhost and blahblah.test domains. I configured Laravel’s APP_URL as “http://blahblah.test”. And ran @php artisan ziggy:generate "resources/js/ziggy.js" via Composer post-autoload-dump script. Well, when I open the site at http://blahblah.test/ I see the correct work of route().current('dashboard') (I have this named route and it exists in resources/js/ziggy.js). But when I open http://localhost/ - the function doesn’t work properly (with any named route). If I set APP_URL to “http://localhost/”, the result is mirrored: works for http://localhost/ and not for http://blahblah.test/.

I should note that I use your library in VueJS environment.

Suggestion

I propose to don’t include domain proto, name, and port to the algorithm of route().current() to give an ability of this function to work on deployment with a lot of different domains which point to the same back-end.

Alternatives

Idk

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I am experiencing a similar issue to this, but between http://testsite.local and http://testsite.local:3000 – in other words, when I am using Browsersync which usually uses port 3000.

Would the issue I am experiencing be covered by what is being discussed in this issue, or should I open up a separate issue and describe things in more detail?

@nevmerzhitsky interesting idea, thanks!

Are there any situations where you think this would be useful besides when switching domains locally as you described? If you run php artisan ziggy:generate during deployment, won’t your frontend always have the correct APP_URL? Thanks!

Yep, deployment in one domain environment works fine. But projects like a platform of landing pages (multiple websites managed by one back-end) will feel this issue. I mean Laravel projects where APP_URL is not defined.

I’m reviewing a PR right now that would change how route().current() would work, so let me see if we can at the very least provide some flexibility with how it matches the path/query versus the entire URL. I could see that kind of flexibility coming in handy (and reducing issues like you’ve had).