仅通过手动将带有相关数据的行插入Laravel/Cashier/Subscription
模型中,如何为条带上的用户创建新订阅。
我已经使用此代码直接从Stripe创建并检索了订阅。
\Stripe\Stripe::setApiKey('sk_test_mykey');
$stripe_sub = \Stripe\Subscription::create([
"customer" => "cus_mycus",
"items" => [
[
"plan" => "plan_myplan",
],
]
]);
$sub = \Stripe\Subscription::retrieve(
$stripe_sub->id
);
现在我想通过执行类似的操作来手动更新订阅表
use Laravel/Cashier/Subscription as CashierSubscription;
public function addSubscription()
{
$subscription = new CashierSubscription;
$subscription->user_id = auth()->user()->id;
$subscription->stripe_plan = $sub->plan;
$subscription->quantity = $sub->quantity;
$subscription->trial_ends_at = $sub->trial_ends;
$subscription->ends_at = $sub->ended_at;
$subscription->save();
但是我得到了这个错误响应
message: Method Illuminate\Database\Eloquent\Collection::save does not exist.
exception: BadMethodCallException
请我如何手动将订阅添加到收银员的订阅模型中。