Does anyone know how to use multi authenticate in laravel 5.2 !
I want to use It but I don't know how ?
does anyone has a tutorial or project setting up multi authentication?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
In most cases I just add a field to the user table called usertype and pass appropriate values like 0=admin, 1=user etc.
This approach helps in avoiding the unnecessary headache of creating different user roles or types.
Though this may not sound ideal, but helps in saving lots of time.
You need two tables
users
andadmins
Run command following command to create built in authTwo models Users(Already exist) and Admin
Now open config/auth.php and make the following changes
Create a new Middleware
RedirectIfNotAdmin
Changes in Kernel.php
Create a new folder Http/Controller/Adminauth and copy the files from Http/Controller/Auth folder
Open the file Http/Controller/Adminauth/AuthController.php and make the following changes
Create new folder Http/Controller/admin, copy Controller.php file in the folder from Http/Controller/
create new file Http/Controller/admin/employee.php
move to resources/views create new folder resources/views/admin copy
resources/views/auth, resources/views/layouts & resources/views/home.blade.php
and post into
resources/views/admin
and open the each file in admin folder and add admin before each path, Now the path should look like@extends('admin.layouts.app')
and your Http/routes.php look like
Thats it open your site in browser and check and for admin yoursiteurl/admin
Enjoy....
First, we create two models: user and admin
Then, we update the config/auth.php file:
Now, modify the app/Http/kernel.php file:
Create
LoginController
and set the following code in it.Note: You have to create login pages for 'user' as well as 'admin'. You then have to submit login form requests to the appropriate controller function i.e.
userLogin()
oradminLogin()
.