简体   繁体   English

受保护的路由上的Laravel 5.2身份验证中间件-显示消息

[英]Laravel 5.2 auth middleware on protected routes - show message

I'm using auth middleware in my routes.php as recommended to enforce login for protected routes. 我建议在我的route.php中使用auth中间件,以强制登录受保护的路由。

Route::group(['middleware' => 'auth'], function () {
Route::resource('message', 'MessageController');
});

So when a protected route is requested if the user is not logged in then the login screen is displayed. 因此,如果用户未登录而请求受保护的路由,则会显示登录屏幕。

In this scenario I would like to add aa to the login view saying something like- 在这种情况下,我想在登录视图中添加aa,例如:

'The page you have requested requires you to login.' “您请求的页面需要您登录。”

If possible I would also like to include the URL that the user has requested. 如果可能的话,我还要包含用户请求的URL。

Any ideas as to how I could achieve this? 关于如何实现此目标的任何想法?

I would just edit your Authenticate middleware to add a redirect message, which you can check for in your login screen: 我只是编辑您的Authenticate中间件来添加重定向消息,您可以在登录屏幕中检查该消息:

redirect()->guest('/')->with('message', 'The page you have requested requires you to login.');

In your login screen: 在您的登录屏幕中:

if(Session::has('message')){
  echo Session::get('message');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM