osb/app/Http/Middleware/Role.php
Deon George 3ff34af7f0
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Update laravel framework from 9 to 11, removed some old packages
2024-07-04 15:03:11 +10:00

35 lines
640 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Closure;
/**
* Enable us to use the role during middleware authorisation
*/
class Role
{
public function handle(Request $request, Closure $next, string $role)
{
if ($role AND ! Auth::user())
abort(403,'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?');
}
}