33 lines
745 B
PHP
33 lines
745 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Middleware;
|
||
|
|
||
|
use Closure;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class IsModerator
|
||
|
{
|
||
|
/**
|
||
|
* Handle an incoming request.
|
||
|
*
|
||
|
* @param \Illuminate\Http\Request $request
|
||
|
* @param \Closure $next
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function handle(Request $request, Closure $next)
|
||
|
{
|
||
|
if ($request->user() && !$request->user()->moderator) {
|
||
|
// This user is not a paying customer...
|
||
|
if ($request->expectsJson()) {
|
||
|
return response([
|
||
|
'message' => 'You are not allowed.',
|
||
|
'type' => 'error',
|
||
|
], 403);
|
||
|
}
|
||
|
return redirect('home');
|
||
|
}
|
||
|
|
||
|
return $next($request);
|
||
|
}
|
||
|
}
|