在Laravel 5中注册时为新用户分配计划

时间:2015-04-10 15:03:25

标签: php laravel laravel-5

当新用户注册时,应自动将其分配给计划订阅。我可以在Tinker(Laravel 5)中手动完成:

  $token = Input::get('stripeToken');
  $user = User::all();
  $user->subscription('monthly')->create($token);

  flash('Your account has been created with a membership');

在Laravel 5中,我是否放置了这样的逻辑?

修改

public function create(array $data)
{

    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
       'company_name' => $data['company_name'],
        // I have added the below:
        $token = Input::get('stripeToken');
       $user = User::all();
       $user->subscription('loop')->create($token);
    ]);

}

1 个答案:

答案 0 :(得分:0)

如果您使用的是Laravels Registrar服务,那么我会在那里进行。这看起来像这样:

public function create(array $data)
{
    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'company_name' => $data['company_name']
    ]);
    $token = Input::get('stripeToken');
    $user->subscription('loop')->create($token);
    return $user;
}

您可能还希望从stripeToken数组中获取$data,但我会将其留给您。