Lars-Janssen
2 years ago

A more Laravel way

Posted 2 years ago by Lars-Janssen

Hello,

What would be more the laravel way of doing this?:

/**
 * Subscribe to a forum
 *
 * @param Forum $forum
 * @return bool
 */
public function subscribe(Forum $forum, $user)
{
    $subscription = new Subscription;
    $subscription->user_id = $user->id;
    $forum->subscriptions()->save($subscription);
}

The relation between forum and subscription is like this:

/**
 * @return mixed
 */
public function subscriptions()
{
    return $this->morphMany(Subscription::class, 'subscription');
}

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