Ad

Laravel 5.2 Custom Authentication

I'm using a table named admins to store name|email|password|contact of all the admins instead of the built in users table provided by Laravel and my login/logout controller code is given below.

It's not working perfectly and not even throwing any error. Do I need to configure config/auth.php file for this? If I need to then what should it look like? And suppose I have another table for managers and they have name|email|password|contactlike admins. How can I configure them?

AdminloginController:

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

Answer

If you have multiple tables with same columns you should rather not create many tables. It would be better if you use one table (might be default users) and for each user set also role (either admin or manager). It might not make any point to create multiple users tables. Consider also that in future you might need also different type of managers etc. and you will finally have a few users table instead of one.

You should really consider this when you don't have more tables yet to not have do many changes in your code in future.

Ad
source: stackoverflow.com
Ad