1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace {$namespace}\Controllers; |
|
|
|
|
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers; |
6
|
|
|
use {$namespace}\User; |
7
|
|
|
|
8
|
|
|
class RegisterController extends Controller |
9
|
|
|
{ |
10
|
|
|
/* |
11
|
|
|
|-------------------------------------------------------------------------- |
12
|
|
|
| Register Controller |
13
|
|
|
|-------------------------------------------------------------------------- |
14
|
|
|
| |
15
|
|
|
| This controller handles the registration of new users as well as their |
16
|
|
|
| validation and creation. By default this controller uses a trait to |
17
|
|
|
| provide this functionality without requiring any additional code. |
18
|
|
|
| |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use RegistersUsers; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Where to redirect users after login / registration. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $redirectTo; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create a new controller instance. |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function __construct() |
36
|
|
|
{ |
37
|
|
|
$this->redirectTo = addon()->config('addon.routes.home', '/home'); |
38
|
|
|
|
39
|
|
|
$this->middleware('guest'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Show the application registration form. |
44
|
|
|
* |
45
|
|
|
* @return \Illuminate\Http\Response |
46
|
|
|
*/ |
47
|
|
|
public function showRegistrationForm() |
48
|
|
|
{ |
49
|
|
|
return view('{$addon_name}::register'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get a validator for an incoming registration request. |
54
|
|
|
* |
55
|
|
|
* @param array $data |
56
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
57
|
|
|
*/ |
58
|
|
|
protected function validator(array $data) |
59
|
|
|
{ |
60
|
|
|
return Validator::make($data, [ |
61
|
|
|
'name' => 'required|max:255', |
62
|
|
|
'email' => 'required|email|max:255|unique:users', |
63
|
|
|
'password' => 'required|confirmed|min:6', |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Create a new user instance after a valid registration. |
69
|
|
|
* |
70
|
|
|
* @return \{$namespace}\User |
71
|
|
|
* @param array $data |
72
|
|
|
*/ |
73
|
|
|
protected function create(array $data) |
74
|
|
|
{ |
75
|
|
|
return User::create([ |
76
|
|
|
'name' => $data['name'], |
77
|
|
|
'email' => $data['email'], |
78
|
|
|
'password' => bcrypt($data['password']), |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.