Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Last active February 9, 2019 05:24
Show Gist options
  • Save JeffreyWay/6510028 to your computer and use it in GitHub Desktop.
Save JeffreyWay/6510028 to your computer and use it in GitHub Desktop.
How might you further refactor this code?
<?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!');
}
@santiblanko
Copy link

with the repository pattern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment