我想知道如何在用户身份验证时运行函数,
这是我的日志函数
public function redirectPath()
{
if (Auth::user()->hasRole('admin')){
$bitacora = TblBitacora::create([
'accion' => 'Inicio de Sesión Admin Exitoso',
'user_id' => Auth::id(),
'ip' => \Request::ip(),
]);
return '/';
}
}
我想运行这个脚本
@if(Auth::user()->??????????????????????????????????????????
<script>
$(function() {
$('#mostrarmodal').modal('show');
});
</script>
@endif
最佳答案
Laravel 有身份验证指令
The @auth and @guest directives may be used to quickly determine if the current user is authenticated or is a guest:
@auth
// The user is authenticated...
@endauth
@guest
// The user is not authenticated...
@endguest
更多信息请访问 https://laravel.com/docs/5.8/blade
另外,我不建议在 Controller 中登录redirectPath方法。您可以使用事件,Laravel 文档中提供了与您想要实现的类似的示例。 https://laravel.com/docs/5.7/events#event-subscribers
关于javascript - 当用户验证 Laravel 时如何运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60210880/