duanfu7994
2016-03-08 07:12
浏览 82
已采纳

在Laravel中back()不为null时重定向

When I dd(back()) it shows all inside back() and one of its key is _previous which I want to use.

My code:

if($request->session()->attributes['_previous'] !== NULL)
// go back
else
// go to specific page

My problem:

The attributes is protected and I couldn't use _previous to go back if it's not null. Is there any suggestion I can use or some other approaches?

Appreciation

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxiong1994 2016-03-08 08:05
    已采纳

    I'd just use back(), because I can't see any scenario when you want to redirect and have NULL back() at the same time.

    If you want to check referrer, you can you something like this:

    if($_SERVER['HTTP_REFERER']){
        Redirect::back();
    }else{
        Redirect::route('main.page');
    }
    

    BTW, if you want to check something for NULL (not just false), you should use is_null function: https://secure.php.net/manual/ru/function.is-null.php

    点赞 打赏 评论

相关推荐 更多相似问题