Laravel 5.7无法声明使用中的类名

时间:2018-12-19 15:01:10

标签: laravel controller laravel-5.7 laravel-controller

我正在尝试在我的网站中进行多次身份验证;我希望一个视图以用户身份登录,另一个视图以客户端身份登录。我有一个用户表,并用代码而不是邮件和mtpass而不是密码创建了一个客户表。

ClientLoginController

<?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'));
    }
}

LoginController

<?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,因为该名称已在使用中

有人可以帮助我修复并了解正在发生的事情吗?谢谢大家!

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,

不能通过作曲家的转储自动加载来解决

然后使用此解决方案

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