<?php

namespace Sargilla\Flatlab4\Middlewares;

use Closure;
use Illuminate\Http\Request;
use Artdarek\Toastr\Facades\Toastr;

class MenuMiddleware
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, Closure $next): mixed
    {
        if (!\Auth::user()->hasPermissionTo('admin-menu'))
        {
            Toastr::error('No tiene permiso para entrar a esta sección!')->push();
            return back();
        }
        return $next($request);
    }
}
