|
@@ -2,9 +2,8 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
+use App\Http\Requests\RegistrationForm;
|
|
use App\Mail\Welcome;
|
|
use App\Mail\Welcome;
|
|
-use App\User;
|
|
|
|
-use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class RegistrationController extends Controller
|
|
class RegistrationController extends Controller
|
|
{
|
|
{
|
|
@@ -13,30 +12,22 @@ class RegistrationController extends Controller
|
|
return view('registration.create');
|
|
return view('registration.create');
|
|
}
|
|
}
|
|
|
|
|
|
- public function store(Request $request)
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Submitted data validation:
|
|
|
|
+ * - now in RegistrationRequest::rules().
|
|
|
|
+ * - the code in this method won't be run if validation fails.
|
|
|
|
+ * - validation is found by Reflection on the method type hint.
|
|
|
|
+ */
|
|
|
|
+ public function store(RegistrationForm $request)
|
|
{
|
|
{
|
|
- // Validate submitted data.
|
|
|
|
- $this->validate($request, [
|
|
|
|
- 'name' => 'required',
|
|
|
|
- 'email' => 'required|email',
|
|
|
|
- // "confirmed" uses <field>_confirmation.
|
|
|
|
- 'password' => 'required|confirmed',
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- // Create user. This would give us a clear password.
|
|
|
|
- // $user = User::create($request->only(['name', 'email', 'password']));
|
|
|
|
- $user = User::create([
|
|
|
|
- 'name' => $request->get('name'),
|
|
|
|
- 'email' => $request->get('email'),
|
|
|
|
- 'password' => bcrypt($request->get('password')),
|
|
|
|
- ]);
|
|
|
|
|
|
+ $user = $request->persist();
|
|
|
|
|
|
// Sign user in.
|
|
// Sign user in.
|
|
auth()->login($user);
|
|
auth()->login($user);
|
|
|
|
|
|
\Mail::to($user)->send(new Welcome($user));
|
|
\Mail::to($user)->send(new Welcome($user));
|
|
|
|
|
|
- // Redirect to home page.
|
|
|
|
|
|
+
|
|
return redirect()->home();
|
|
return redirect()->home();
|
|
}
|
|
}
|
|
}
|
|
}
|