I'm trying to perform the login of the user but the attempt always returns false
CONTROLLER
public function login(Request $request)
{
$validator = Validator($request->all(),[
'username' => 'required',
'password' => 'required|alpha_num',
]);
if ($validator->fails()){
dd($validator->messages()->toJson());
}else{
User::login($request);
dd(Auth::check());
}
}
MODEL
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Auth;
class User extends Authenticatable
{
protected $table = 'user';
protected $primaryKey = 'Id';
public $timestamps = false;
/** The rules to validate a new user
* @var array
*/
static $rulesRegister = array(
'username' => 'required|unique:user,Username',
'password' => 'required|alpha_num',
'email' => 'required|email|unique:user,Email',
);
/** Login the user in the App
* @param Request $request
* @return Return True or False (?, need dd)
*/
static function login(Request $request)
{
Auth::attempt([
'Username' => $request->input('username'),
'Password' => $request->input('password')
]
,true);
}
FORM
<form method="post" action="{{ route('login') }}">
{{ csrf_field() }}
<input type="text" id="username" name="username" value="">
<input type="password" id="password" name="password" value="">
<button type="submit">
Login
</button>
</form>
ROUTES
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('index');
})->name('index');
Route::post('/login', 'UserController@login')->name('login');
});
I already debuged the DatabaseUserProvider -> method retrieveByCredentials(array $credentials) and the credentials or query is always null, i already tried to rename my Password and Username to all lower case (in database and in the attempt() method), i tried to attempt with and without bcrypt, tried by Email i can't seem to find what is happening