-1

I have a URL with a defined route which can be accessed through the browser by entering the url or through a view. I need to check if that URL was accessed using a browser(entering a url) or through a view triggered by an action of the user.

Is that a way to do that in Laravel ?

MaartenDev
  • 5,093
  • 5
  • 20
  • 31
Xunita
  • 67
  • 9
  • you mean when users click on a url/button? This could be solved by using something like the referrer url: https://stackoverflow.com/questions/16374704/php-how-to-get-referrer-url/16374737 – MaartenDev Dec 31 '19 at 11:02

1 Answers1

0

You can check for the existence of a previous url

Route::get('test', function () {
    if (url()->previous() === config('app.url')) {
        dd('accessed from browser');
    } else {
        dd('accessed from view');
    }
});

Hope this helps

Salim
  • 9,886
  • 5
  • 23
  • 55