javascript - 当用户验证 Laravel 时如何运行脚本?

标签 javascript laravel

我想知道如何在用户身份验证时运行函数,

这是我的日志函数

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/

相关文章:

javascript - JQuery 验证插件 submitHandler 对我不起作用

javascript - 选中复选框时启用下拉菜单

javascript - Prototype.js 或其他 js 函数来解码 html 实体

php - Laravel 5.5 在按一个字段进行分组后获取索引键编号

php - Laravel 5.5 和子域 session ?

javascript - 如何制作图像卡并使其显示在同一页面上

javascript - 如何在 nodejs 模块中监视类方法

php - Laravel:队列作业表修改字段问题

php - 如何在 Laravel 中使用 NewsAPI

php - 更新用户时对 Laravel 空密码进行哈希处理