Skip to content

Instantly share code, notes, and snippets.

@RimonEkjon
Forked from JeffreyWay/refactor.php
Created August 26, 2014 07:42
Show Gist options
  • Save RimonEkjon/2ea26e4b41e05092709d to your computer and use it in GitHub Desktop.
Save RimonEkjon/2ea26e4b41e05092709d to your computer and use it in GitHub Desktop.
<?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