Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created January 9, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/e5b7a5b97575a33624730fdee940406f to your computer and use it in GitHub Desktop.
Save uno-de-piera/e5b7a5b97575a33624730fdee940406f to your computer and use it in GitHub Desktop.
Autenticar usuarios en Laravel 5 manualmente
<?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