简体   繁体   English

未经身份验证的消息Laravel 5.6(PHP)

[英]Not authenticated message Laravel 5.6 (PHP)

I am new in Laravel and using 5.6 version . 我是Laravel的新手,并且使用5.6版本 I want that if user goes to a specific page that is authenticated it should redirect to login page and show a flash message for example the user goes to create post page which is authenticated and user is not authenticated so the login form is showed but I want a flash message also show on login page can anyone tell me where to set that message??? 我希望如果用户转到经过身份验证的特定页面,则应重定向到登录页面并显示一条快速消息,例如,该用户创建了经过身份验证且未经过身份验证的帖子页面,因此显示了登录表单,但我想要在登录页面上还会显示一条Flash消息,有人可以告诉我在哪里设置该消息吗???

Note: I'm using the built in Laravel Login sytem nothing changed! 注意:我使用的是内置的Laravel登录系统,没有任何改变!

Laravel default authentication supports events. Laravel默认身份验证支持事件。 When user failed to authenticate the App\\Listeners\\LogFailedLogin event is being dispatched. 当用户未能通过身份验证时,将调度App\\Listeners\\LogFailedLogin事件。 You can hook your handler to that event and set session flash message there. 您可以将处理程序挂接到该事件,并在那里设置会话刷新消息。

You can set the message as a normal html code in your login page and put the @guest...@endguest 您可以在登录页面中将消息设置为普通的html代码,然后将@guest...@endguest

For Example : 例如 :

<div class="alert alert-danger">
    <h2 class="text-center">Your Message here !!</h2> <!-- This is only a way to show u , it doesn't have to be like this-->
</div>

Hopefully this will work for you 希望这对你有用

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

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