5

Say i have localhost/public/admin that redirects immediately to localhost/public/user/login.

How am I going to get the admin value in user/login?

tereško
  • 58,060
  • 25
  • 98
  • 150
user2002495
  • 2,126
  • 8
  • 31
  • 61

1 Answers1

14

You'll need to grab the referer and check if it is contains 'admin'. Try the following

$referer = Request::referer();
// or
// $referer = Request::server('HTTP_REFERER');

if (strpos($referer,'admin') !== false) {
    dd('coming from admin')
}

Edit #1: As pointed out by @tomvo you can also use URL::previous() instead of Request::referer() in L4

Edit #2: It's actually mispelled as referer instead of referrer as point out by @JamesF

Edit #3: In Laravel 5 the Request::referer() method doesn't seem to exist anymore, you can still get it by using Request::header('referer') as point out by @TheSerenin

afarazit
  • 4,907
  • 2
  • 27
  • 51
  • 3
    which would be `URL::previous()` in L4 – tomvo Apr 09 '15 at 07:24
  • Looks like it's `Request::referer()` with one 'r' - strange mis-spelling in the original spec (https://en.wikipedia.org/wiki/HTTP_referer) – James F Sep 08 '15 at 15:44
  • 5
    In Laravel 5 the `Request::referer()` method doesn't seem to exist anymore, you can still get it by using `Request::header('referer');` – MisterBla Sep 18 '15 at 08:08
  • `Request::server('HTTP_REFERER')` helped me: https://stackoverflow.com/a/45713501/470749 – Ryan Oct 17 '17 at 22:43