<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class CanOnWebGuard
{
    public function handle($request, Closure $next, $permission)
    {
        $user = Auth::guard('web')->user();

        // Use can() instead of hasPermissionTo() to work with Gate definitions
        // can() is more flexible and works with the multi-guard permission system
        if (!$user || !$user->can($permission)) {
            abort(403, 'Unauthorized action.');
        }

        return $next($request);
    }
}
