30 lines
798 B
PHP
30 lines
798 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class CanOnWebGuard
|
|
{
|
|
public function handle($request, Closure $next, ...$permissions)
|
|
{
|
|
$user = Auth::guard('web')->user();
|
|
|
|
if (!$user) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
// Use can() instead of hasPermissionTo() to work with Gate definitions
|
|
// can() is more flexible and works with the multi-guard permission system.
|
|
// Multiple middleware params are treated as "any of" (e.g. `user.can:access profiles,access accounts`).
|
|
foreach ($permissions as $permission) {
|
|
if ($user->can($permission)) {
|
|
return $next($request);
|
|
}
|
|
}
|
|
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
}
|