Last active
February 9, 2019 05:24
-
-
Save JeffreyWay/6510028 to your computer and use it in GitHub Desktop.
How might you further refactor this code?
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
with the repository pattern?