Laravel 4 how check if a route only comes/redirected from another route?

亡梦爱人 提交于 2019-12-07 04:18:03

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/23195987/laravel-4-how-check-if-a-route-only-comes-redirected-from-another-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!