Laravel 5.2 自定义身份验证

Laravel 5.2 Custom Authentication

我正在使用名为 admins 的 table 来存储所有管理员的 name|email|password|contact,而不是 Laravel 提供的内置用户 table我的 login/logout 控制器代码如下。

它运行不正常,甚至没有抛出任何错误。我需要为此配置 config/auth.php 文件吗?如果我需要那么它应该是什么样子?假设我有另一个 table 的经理,他们有 name|email|password|contact 类似的管理员。我该如何配置它们?

管理员登录控制器:

<?php

namespace App\Http\Controllers;


use App\Model\Admin;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;

class AdminLoginController extends Controller
{
    public function postLogin(Request $request){
        if(Auth::attempt(['email'=> $request->email,'password'=> $request->password])){
            return redirect('/AdminPanel');
        }
        return redirect()->back();
    }
    public function getLogout(Request $request){
        Auth::logout();
        return redirect('/');
    }
}

如果您有多个具有相同列的 table,您最好不要创建很多 table。如果您使用一个 table(可能是默认的 users)并为每个用户设置角色(adminmanager)会更好。创建多个用户 tables 可能没有任何意义。还要考虑到将来您可能还需要不同类型的经理等,您最终将拥有几个用户 table 而不是一个。

当您还没有更多 table 并且将来不会对您的代码进行太多更改时,您应该真正考虑这一点。