for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Http\Middleware;
use Auth;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
* Create a new filter instance.
* @param Guard $auth
* @return void
public function __construct(Guard $auth)
$this->auth = $auth;
}
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $role
* @return mixed
public function handle($request, Closure $next, $role)
$role
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function handle($request, Closure $next, /** @scrutinizer ignore-unused */ $role)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
if (!$this->auth->check()) {
return redirect()->to('/login')
->with('status', 'success')
->with('message', 'Please login.');
////////////////
// if($role == 'all')
// {
// return $next($request);
// }
// if( $this->auth->guest() || !$this->auth->user()->hasRole($role))
// abort(403);
return $next($request);
public function terminate($request, $response)
$response
public function terminate($request, /** @scrutinizer ignore-unused */ $response)
$request
public function terminate(/** @scrutinizer ignore-unused */ $request, $response)
$user = Auth::user();
$currentRoute = Route::currentRouteName();
Log::info('Authenticate middlware was used: '.$currentRoute.'. ', [$user]);
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.