Laravel 5 - how to use basic auth with username in place of email?

Jeremy Belolo picture Jeremy Belolo · May 21, 2015 · Viewed 9k times · Source

Hello guys !

So in Laravel 4 we could do

Route::filter('auth.basic', function()
{
    return Auth::basic('username');
});

But now it's not possible, and the doc doesn't give a clue about how to. So can anyone help ?

Thanks !

Answer

Davor Minchorov picture Davor Minchorov · May 21, 2015

Create a new custom middleware using the same code as the default one:

https://github.com/laravel/framework/blob/5.0/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php

and override the default 'email' field like:

return $this->auth->basic('username') ?: $next($request);