Created
January 9, 2018 10:54
-
-
Save uno-de-piera/e5b7a5b97575a33624730fdee940406f to your computer and use it in GitHub Desktop.
Autenticar usuarios en Laravel 5 manualmente
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::post('login', function() { | |
$validator = \Validator::make(request()->all(), [ | |
'email' => 'required', | |
'password' => 'required' | |
]); | |
if ($validator->fails()) { | |
//mostrar errores, o en json o lo que necesites | |
} | |
$userData = \App\User::where('email',request('email'))->first(); | |
if ($userData && \Hash::check(request('password'), $userData->password)) | |
{ | |
auth()->loginUsingId($userData->id); | |
//log que necesites | |
} | |
//si estás aquí algo ha salido mal, 404, 401, 403?? | |
})->middleware('guest'); //sólo para invitados! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment