File: D:/HostingSpaces/SBogers85/equichecker.com/app/Http/Middleware/Authenticate.php
<?php
namespace App\Http\Middleware;
use Closure;
use Kbwebs\MultiAuth\MultiManager;
use Illuminate\Foundation\Application;
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Authenticate constructor
* @param \Illuminate\Foundation\Application $app
*/
public function __construct(Application $app)
{
$this->app = $app;
$this->auth = new MultiManager($this->app);
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $role
* @return mixed
*/
public function handle($request, Closure $next, $role)
{
switch ($role) {
case 'user':
return $this->handleUser($request, $next);
break;
case 'customer':
//return view('welcome');
return $this->handleCustomer($request, $next);
break;
}
}
private function handleUser($request, Closure $next)
{
if (!$this->auth->user()->guest()) return $next($request);
if ($request->ajax()) return response('Unauthorized.', 401);
return redirect()->guest('kms/login');
}
private function handleCustomer($request, Closure $next)
{
if (!$this->auth->customer()->guest()) return $next($request);
if ($request->ajax()) return response('Unauthorized.', 401);
$controller = \App::make('KommaApp\Pages\PageController');
return $controller->index();
}
}