osb/app/Http/Middleware/Role.php
2018-07-31 14:11:00 +10:00

31 lines
534 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Support\Facades\Auth;
use Closure;
class Role
{
public function handle($request, Closure $next, $role)
{
if ($role AND ! Auth::user())
return abort(303,'Not Authenticated');
switch ($role) {
case 'wholesaler':
if (Auth::user()->role() == $role)
return $next($request);
break;
case 'reseller':
if (in_array(Auth::user()->role(),['wholesaler','reseller']))
return $next($request);
break;
}
abort(404,'User doesnt have role?');
}
}