Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Last active December 21, 2015 09:19
Show Gist options
  • Save tournasdim/6284453 to your computer and use it in GitHub Desktop.
Save tournasdim/6284453 to your computer and use it in GitHub Desktop.
L4 Authentication example (into the route.php)
<?php
//Laravel 4 Validation example
Route::post('register', function() {
$rules = array(
'name' => 'required|min:3|max:80|alpha_dash',
'email' => 'required|between:3,64|email|unique:users',
'password' => 'required|alpha_num|between:4,8|confirmed',
'password_confirmation' => 'required|alpha_num|between:4,8'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
User::create(array(
'name' => Input::get('name'),
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'))
));
return Redirect::to('/')->with('message','Thanks for registering!');
} else {
return Redirect::to('/')->withErrors($validator->getMessages());
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment