-
-
Save RimonEkjon/2ea26e4b41e05092709d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// .... | |
/** | |
* Register a new subscriber | |
* | |
* @return Response | |
*/ | |
public function store() | |
{ | |
$input = Input::all(); | |
// If the user doesn't validate, get out of here | |
if (User::isInvalid($input)) | |
{ | |
return Redirect::back() | |
->withErrors(User::$validation) | |
->withInput(); | |
} | |
// Now, let's try to subscribe them | |
$subscription = $this->billing->subscribeUser(); | |
// If an error occurred, go back and tell the user | |
if ($subscription->error) | |
{ | |
return Redirect::back() | |
->with('flash_message', $subscription->error); | |
} | |
// Otherwise, create the new user | |
$user = $this->user->create([ | |
'subscription_id' => 1, | |
'billing_id' => $subscription->customer->id, | |
'username' => $input['username'], | |
'email' => $input['email'], | |
'password' => Hash::make($input['password']), | |
'active' => 1, | |
'last_logged_in' => new DateTime | |
]); | |
// Then log them in | |
Auth::login($user); | |
// And finally redirect to lessons page with message | |
return Redirect::to('lessons') | |
->with('flash_message', 'You are now a Laracasts member!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment