1. Go to this page and download the library: Download bogardo/multiauth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Bogardo\Multiauth\User\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface
{
use UserTrait, RemindableTrait;
public $authtype = 'user';
}
use Bogardo\Multiauth\User\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Admin extends Eloquent implements UserInterface, RemindableInterface
{
use UserTrait, RemindableTrait;
public $authtype = 'administrator';
}
$entities = $service->getEntities();
// $entities Output
object(Bogardo\Multiauth\Entity\EntityCollection)
protected 'items' =>
array (size=2)
0 =>
object(Bogardo\Multiauth\Entity\Entity)
public 'type' => string 'user'
public 'table' => string 'users'
public 'model' => string 'User'
public 'identifier' => string 'username'
1 =>
object(Bogardo\Multiauth\Entity\Entity)
public 'type' => string 'administator'
public 'table' => string 'admins'
public 'model' => string 'Admin'
public 'identifier' => string 'email'
$entity = $service->getEntityByType('user');
// $entity Output
object(Bogardo\Multiauth\Entity\Entity)
public 'type' => string 'user'
public 'table' => string 'users'
public 'model' => string 'User'
public 'identifier' => string 'username'
/** @var Bogardo\Multiauth\Service $service */
$service = App::make('multiauth.service');
$types = $service->getEntities()->lists('type');
foreach ($types as $type) {
Route::filter('multiauth.' . $type, function($route, $request) use ($type) {
if (Auth::guest()) {
// The user is not logged in.
return Redirect::to('/');
}
if (Auth::user()->authtype !== $type) {
// The user is logged in, but is not of correct type
return Redirect::to('/');
}
});
}