使用Laravel 8和Jetstream将自定义数据传递到login.blade.php

问题描述

缺少实现自己的登录控制器的方法,是否可以通过Laravel 8和Jetstream(Livewire)将数据传递到 views / auth / login.blade.php 中?

在Laravel 7中,LoginController具有一个showLoginForm()方法,您可以重写该方法,并仅返回包含其他数据的视图。使用Jetstream似乎并不那么简单。

解决方法

Recent updates to Jetstream / Fortify已解决了这个问题。

,

这是我解决的方法:(通过laravel管道的概念)

public function showLoginForm()
    {
        return view('admin.auth.login');
    }

    public function logout()
    {
        Session::flush();
        Auth::logout();
        return redirect('admin/login');
    }

    public function login(Request $request)
    {
        return $this->loginPipeline($request)->then(function ($request) {
            return app(LoginResponse::class);
        });
    }

    protected function loginPipeline($request)
    {
        if (Fortify::$authenticateThroughCallback) {
            return (new Pipeline(app()))->send($request)->through(array_filter(
                call_user_func(Fortify::$authenticateThroughCallback,$request)
            ));
        }

        if (is_array(config('fortify.pipelines.login'))) {
            return (new Pipeline(app()))->send($request)->through(array_filter(
                config('fortify.pipelines.login')
            ));
        }

        return (new Pipeline(app()))->send($request)->through(array_filter([
            config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,RedirectIfTwoFactorAuthenticatable::class,AttemptToAuthenticate::class,PrepareAuthenticatedSession::class,]));
    }

如果要自定义字段,请说“状态” =>“活动”。然后,您需要将RedirectIfTwoFactorAuthenticatable复制到actions文件夹。并执行以下操作:

 return tap($model::where(Fortify::username(),$request->{Fortify::username()})
            ->where('status','active')
            ->first(),function ($user) use ($request) {
            if (!$user || !Hash::check($request->password,$user->password)) {
                $this->throwFailedAuthenticationException($request);
            }
        });

享受:)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...