first(); } /** * @param string $title * * @return ObjectGroup|null */ protected function findOrCreateObjectGroup(string $title): ?ObjectGroup { $group = null; $maxOrder = $this->getObjectGroupMaxOrder(); if (!$this->hasObjectGroup($title)) { return ObjectGroup::create( [ 'title' => $title, 'order' => $maxOrder + 1, ] ); } return $this->findObjectGroup($title); } /** * @return int */ protected function getObjectGroupMaxOrder(): int { return (int) ObjectGroup::max('order'); } /** * @param string $title * * @return bool */ protected function hasObjectGroup(string $title): bool { return 1 === ObjectGroup::where('title', $title)->count(); } }