1

我正在尝试在我的网站上进行多重身份验证;我希望以用户身份查看日志,以客户端身份查看日志。我有一个用户表,我用代码而不是邮件和 mtpass 而不是密码创建了一个客户端表。

客户端登录控制器

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller as CltController;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ClientLoginController extends CltController
{
    use AuthenticatesUsers;

    public function __construct()
    {
        $this->middleware('auth:client');
    }

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

    public function showClientLoginForm()
    {
        return view('auth.loginClient', ['url' => 'client']);
    }

    public function clientLogin(Request $request)
    {
        $this->validate($request, [
            'Code' => 'required|email',
            'Mtpass' => 'required|min:4'
        ]);

        if (Auth::guard('client')->attempt(['Code' => $request->Code, 'Mtpass' => $request->Mtpass], $request->get('remember'))) {

            return redirect()->intended('/main');
        }
        return back()->withInput($request->only('Code', 'remember'));
    }
}

登录控制器

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
        $this->middleware('guest:client')->except('logout');
    }

    public function showClientLoginForm()
    {
        return view('auth.loginClient', ['url' => 'client']);
    }

    public function clientLogin(Request $request)
    {
        $this->validate($request, [
            'Code' => 'required|email',
            'Mtpass' => 'required|min:4'
        ]);

        if (Auth::guard('client')->attempt(['Code' => $request->Code, 'Mtpass' => $request->Mtpass], $request->get('remember'))) {
            return redirect()->intended('/main');
        }

        return back()->withInput($request->only('Code', 'remember'));
    }

    protected function redirectTo()
    {
        $role_id = auth()->user()->role_id;

        if (auth()->check()) {
            switch ($role_id) {
                case 1:
                    return 'admin/profil';
                case 2:
                    return 'client/profil';
                case 3:
                    return 'agent/profil';
            }
        }

        return '/main';
    }
}

我无法弄清楚如何解决以下错误。

无法声明类 App\Http\Controllers\ClientLoginController,因为该名称已在使用中

有人可以帮助我解决并了解正在发生的事情吗?谢谢你们!

4

1 回答 1

0

我有这个问题

composer dump-autoload 无法解决

然后使用此解决方案

https://stackoverflow.com/a/64385832/308578

于 2020-10-16T08:49:44.270 回答