24 lines
538 B
PHP
24 lines
538 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\Menu;
|
|
use Closure;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class CheckPermissions
|
|
{
|
|
public function handle($request, Closure $next, $menu)
|
|
{
|
|
$user = Auth::user();
|
|
$menuId = Menu::where('url', $menu)->value('id');
|
|
|
|
if ($user && $user->userGroup->permissions->contains('menu_id', $menuId)) {
|
|
return $next($request);
|
|
}
|
|
|
|
throw new NotFoundHttpException();
|
|
}
|
|
}
|