@wing5wong What precisely do I do w/ this middleware to make it override the default?
I have run php artisan make:middleware Authenticate, and a standard empty middleware has been created. This doesn't override anything yet, nor does adding extends \Illuminate\Auth\Middleware\Authenticate to the class definition.
Next thing I did was to append this custom Authenticate::class in ./bootstrap/app.php, but this just adds another near copy of the standard "auth" mw to the middleware chain, which in my scenario just causes the login endpoint to get hit repeatedly ad infinitum.
I've also tried $middleware->replace('auth', Authenticate::class); and $middleware->replace(\Illuminate\Auth\Middleware\Authenticate::class, Authenticate::class);, but to zero avail.
đ UPDATE: just made it work with $middleware->alias(['auth' => Authenticate::class]); â is that how I was supposed to do it from the beginning? or did I just hack my way into what could have been done much more easily?
For context, here's what my custom mw looks like:
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\AuthenticationException;
use Log;
class Authenticate extends \Illuminate\Auth\Middleware\Authenticate
{
protected function unauthenticated($request, array $guards)
{
session()->flash('message', 'Login first');
Log::debug('hello...');
throw new AuthenticationException(
'Unauthenticated.',
$guards,
$this->redirectTo($request)
);
}
}