/** * Subscribe to category with provided title * * @param $user * @param $title */ private function subscribe(\User $user, $title) { if (!$user->subscriptions()->whereRaw("LOWER(title) = LOWER(?)", [$title])->first()) { if ($category = Category::whereRaw("LOWER(title) = LOWER(?)", [$title])->first()) { $user->subscriptions()->attach($category->id); } } }