简体   繁体   English

身份验证中间件的登录模板中的自定义错误消息

[英]Custom error message in login template in auth middleware

I've grouped certain routes that require the user to be logged in before they perform some action. 我对某些路由进行了分组,这些路由要求用户在执行某些操作之前先登录。

Route::group(['middleware' => 'auth'], function() {
      Route::get('/posts/create', 'PostController@create');
});

Now when the user visits this url, he'll be redirected to the login page if the user is not logged in. But I want to display a custom error message saying you've to be logged in to perform this action in an error block. 现在,当用户访问该URL时,如果用户未登录,他将被重定向到登录页面。但是我想显示一条自定义错误消息,指出您必须登录才能在错误块中执行此操作

Where can I pass the custom message to the login view before redirecting? 重定向之前,我在哪里可以将自定义消息传递到登录视图?

Note: I know it's obvious that if the user lands on the create post page with a login form, it indicates that the user should login. 注意:我知道很明显,如果用户使用登录表单登录到create post页面,则表明该用户应该登录。 Still, that error form is required . 仍然required该错误形式。

When you're redirecting add with() clause to flash a message to the session: 重定向时,添加with()子句将一条消息刷新到会话中:

return redirect()->with('message', 'You've to be logged in to perform this action');

In 5.2 you may want to override one of the login related methods (it depends on what you're trying to achieve) in the Auth\\AuthController.php . 在5.2中,您可能想覆盖Auth\\AuthController.php中与登录相关的方法之一(取决于您要实现的目标)。 In 5.3 do the same in the Auth\\LoginController.php 在5.3中,在Auth\\LoginController.php执行相同的操作

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

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