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\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
class Authenticate extends Middleware
{
/**
* 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;
}
* Get the path the user should be redirected to when they are not authenticated.
* @param \Illuminate\Http\Request $request
* @return string|null
protected function redirectTo($request)
if (! $request->expectsJson()) {
return route('login');
* Handle an incoming request.
* @param \Closure $next
* @return mixed
public function handle($request, Closure $next)
if (! $this->auth->check()) {
return redirect()->to('/login')
->with('status', 'success')
->with('message', 'Please login.');
return $next($request);
* Log a termination.
* @param $response
public function terminate($request, $response)
$response
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function terminate($request, /** @scrutinizer ignore-unused */ $response)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
$request
public function terminate(/** @scrutinizer ignore-unused */ $request, $response)
$user = Auth::user();
$user
$currentRoute = Route::currentRouteName();
$currentRoute
// Log::info('Authenticate middleware 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.