Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Routes + Controller para login básico no Laravel 4.
//Routes.php
/* login */
Route::get('login', 'BaseController@getLogin');
Route::post('login', ['before' => 'csrf', 'uses' => 'BaseController@postLogin']);
//LoginController.php
class LoginController extends BaseController
{
public function getLogin()
{
return View::make('login');
}
public function postLogin()
{
$regras = array("email" => "required|email",
"senha" => "required");
$validacao = Validator::make(Input::all(), $regras);
if ($validacao->fails()) {
return Redirect::to('login')->withErrors($validacao);
}
//tenta logar o usuário
if (Auth::attempt( array('email' => Input::get('email'), 'password' => Input::get('senha') ) ) ) {
return Redirect::to('/');
}
else {
return Redirect::to('login')->withErrors('Usuário ou Senha Inválido');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.