Initial commit
This commit is contained in:
22
app/Http/Middleware/CanOnWebGuard.php
Normal file
22
app/Http/Middleware/CanOnWebGuard.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user