【问题标题】:Laravel Redirect when Middleware Process checking中间件进程检查时的 Laravel 重定向
【发布时间】:2015-10-29 11:23:57
【问题描述】:

我正在开发一个业务目录的 laravel web 应用程序。

这是我的场景。

  1. http://localhost/genie-works/devojp/customer // 用户使用企业关键字搜索和

  2. http://localhost/genie-works/devojp/customer/search-result?keyword=apple&searchcity=1此页面中显示结果。

  3. 此处列出了太多带有发布查询功能的业务数据。

  4. 点击帖子时,查询按钮页面会转到http://localhost/genie-works/devojp/customer/post-enquiry/{bisinjessid}/

  5. 帖子查询页面检查中间件作为身份验证。

  6. 当用户未登录中间件时重定向到登录页面http://localhost/genie-works/devojp/customer并显示登录表单

  7. 输入登录详细信息后,需要重定向到http://localhost/genie-works/devojp/customer/post-enquiry/{bisinjessid}/此页面。

  8. 但我尝试了 Redirect::back 功能,将其重定向到客户页面 (http://localhost/genie-works/devojp/customer)

    如何通过重定向到我的最后一页来解决此问题....

谢谢

中间件..

 public function handle($request, Closure $next)
 {
    if (!Auth::check()) {
        return redirect()->intended(route('cust_index'))->with('activelogin','Succesfully LoggedOut !!!');
        }
    return $next($request);
 }

控制器..

public function custdologin(){
    $userdata=array(
    'username'=>Input::get('email'),   // getting data from form
    'password'=>Input::get('password')   // getting data from form
    );
    if(Auth::attempt($userdata)){
        switch (Auth::user()->user_type) {
            case '2':

                return Redirect::to(route('myaccount'));
                break;
            case '3':
                return back();
                break;
            default:
                Auth::logout();
                return Redirect::to(route('business_login'))->with('message','Check Your Entries!!');
                break;
        }
    }   
    else
    return Redirect::to(route('business_login'))->with('message','Check Your Entries!!');
}

【问题讨论】:

  • 使用redirect()->intended()而不是重定向回来

标签: authentication laravel-5 middleware


【解决方案1】:

在您使用重定向的中间件中,使用以下内容:

return redirect()->intended('put a default url'); // i.e: '/dashboard'

这会将用户重定向到他想在不登录的情况下访问的预期 URL。Check more here(在Manual Authentication 代码 sn-p 中)

【讨论】:

  • 不工作.. 更新了我有问题的中间件和控制器
猜你喜欢
  • 2015-05-17
  • 2018-04-24
  • 2020-06-06
  • 2020-06-23
  • 2017-04-22
  • 2017-11-21
  • 2017-03-15
  • 2018-04-14
  • 2018-04-21
相关资源
最近更新 更多