/** * Get last notification of the current * entity of a specific category * * @param $category * @param $to_id * @param $entity * @return mixed */ public function getLastNotificationByCategory($category, $to_id, $entity) { $query = $this->notification->wherePolymorphic($to_id, $entity); if (is_numeric($category)) { return $query->orderBy('created_at', 'desc')->where('category_id', $category)->first(); } return $query->whereHas('body', function ($categoryQuery) use($category) { $categoryQuery->where('name', $category); })->orderBy('created_at', 'desc')->first(); }
/** * Get last notification of the current * entity of a specific category * * @param $category * @param $to_id * @param $entity * @param Closure $filterScope * @return mixed */ public function getLastNotificationByCategory($category, $to_id, $entity, Closure $filterScope = null) { $query = $this->notification->wherePolymorphic($to_id, $entity)->byCategory($category)->orderBy('created_at', 'desc'); $query = $this->applyFilter($filterScope, $query); return $query->first(); }