Регистрация (Laravel) v2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
class RegisterController extends BaseController
{
public function getIndex() {
return View::make('register.index');
}
public function postIndex() {
$rules = array(
'email' => 'required|email|unique:users',
'password' => 'required|alpha_dash|min:8|max:32|confirmed',
'first_name' => 'latter',
'last_name', => 'latter',
);
$inputs = Input::all();
$validator = Validator::make($inputs, $rules);
if ($validator->fails()) {
return Redirect::route('index')
->withInput(Input::except('password'))
->withErrors($validator);
} else {
$user = new User;
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->first_name = Input::get('first_name');
$user->last_name = Input::get('last_name');
$user->save();
return View::make('register.success', $inputs);
}
}
}