b4nghh's avatar

How to check whether a route(URL) is an asset route?

I have a session variable in a BaseController's constructor to store current route. The code is like this:

if (!request()->ajax()) {
      session()->put('current_url', request()->fullUrl());
}
                

But sometimes, I got asset URL like this in the session value:

https://laravel.dev/favicon.ico

I checked url()->full() but its implementation is the same:

/**
     * Get the full URL for the current request.
     *
     * @return string
     */
    public function full()
    {
        return $this->request->fullUrl();
    }

How can I get the current full URL (exclude asset routes) or how can I know whether a route is an asset route or not?

Thanks!

0 likes
4 replies
Snapey's avatar

What you are doing is fundamentally flawed anyway since a user can have two browser tabs open, on the same session, and on totally different pages.

b4nghh's avatar

@Snapey Thank you! I'm aware of that. But I wonder why my code doesn't work as expected. Why it store favicon in my session variable?

Snapey's avatar
Snapey
Best Answer
Level 122

because your .htaccess file will forward requests for missing objects to your index.php file. This in turn will send back a 404 error because you have no route for favicon.ico

If you had a favicon this particuar issue would not happen

b4nghh's avatar

@Snapey It's exactly what I'm looking for. Thank you so much for your explanation.

Please or to participate in this conversation.