How to update a model

Posted 2 months ago by successdav

here is the code to create. I am using polymorphic relationship morphMany();

public function createSubscription($userId = null)
    {
        if (! $this->subscriptions()->where(['user_id' => auth()->id()])->exists()){
            return $this->subscriptions()->save(
                    new Subscription([
                        'user_id' => $userId ?: auth()->id(),
                        'duration' => $this->duration,
                        'subscription_end_at' => Carbon::now()->addMonths($this->duration)
                    ])
            );
        };
    }

now to update I try

$this->subscriptions->where(['user_id' => auth()->id()])->update(['active' => false]);

the second code does not work it says BadMethodCall Exception. update does not exists.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.