staffmanager/app/Http/Middleware/Bancheck.php
Miguel Nogueira 4eb115d165 Revert "Apply fixes from StyleCI (pull request #6)"
This reverts pull request #6.

> This pull request applies code style fixes from an analysis carried out by [StyleCI](https://bitbucket.styleci.io).
> 
> For more information, click [here](https://bitbucket.styleci.io/analyses/a2Jl7D).
2020-10-21 00:29:50 +00:00

40 lines
861 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
class Bancheck
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$userIP = $request->ip();
$anonymousUser = User::where('ipAddress', $userIP)->get();
if (Auth::check() && Auth::user()->isBanned())
{
View::share('isBanned', true);
}
elseif(!$anonymousUser->isEmpty() && User::find($anonymousUser->id)->isBanned())
{
View::share('isBanned', true);
}
else
{
View::share('isBanned', false);
}
return $next($request);
}
}