opnform/app/Http/Middleware/IsModerator.php

32 lines
666 B
PHP
Raw Permalink Normal View History

2024-01-19 13:27:04 +00:00
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class IsModerator
{
/**
* Handle an incoming request.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
2024-02-23 10:54:12 +00:00
if ($request->user() && ! $request->user()->moderator) {
2024-01-19 13:27:04 +00:00
// This user is not a paying customer...
if ($request->expectsJson()) {
return response([
'message' => 'You are not allowed.',
'type' => 'error',
], 403);
}
2024-02-23 10:54:12 +00:00
2024-01-19 13:27:04 +00:00
return redirect('home');
}
return $next($request);
}
}