Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created January 9, 2018 11:03
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/e1c771c537a0dadf0d0987c5ed3f6cf7 to your computer and use it in GitHub Desktop.
Save uno-de-piera/e1c771c537a0dadf0d0987c5ed3f6cf7 to your computer and use it in GitHub Desktop.
Autenticar usuarios en Laravel 5 manualmente con Auth::attempt
<?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
}
if (\Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
return redirect()->intended('¿?'));
}
//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