/** * @param array $fields * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * * @return Tag|null */ public static function firstOrCreateEncrypted(array $fields) { // everything but the tag: if (isset($fields['tagMode'])) { unset($fields['tagMode']); } $query = Tag::orderBy('id'); foreach ($fields as $name => $value) { if ($name != 'tag') { $query->where($name, $value); } } $set = $query->get(['tags.*']); /** @var Tag $tag */ foreach ($set as $tag) { if ($tag->tag == $fields['tag']) { return $tag; } } // create it! $fields['tagMode'] = 'nothing'; $fields['description'] = isset($fields['description']) && !is_null($fields['description']) ? $fields['description'] : ''; $tag = Tag::create($fields); return $tag; }
/** * @param Carbon $date */ protected function createTags(Carbon $date) { Tag::create(['user_id' => $this->user->id, 'tag' => 'SomeTag' . $date->month . '.' . $date->year . '.nothing', 'tagMode' => 'nothing', 'date' => $date->format('Y-m-d')]); }
/** * */ public function createTags() { $user = User::whereEmail('*****@*****.**')->first(); Tag::create(['tag' => 'TagOne', 'tagMode' => 'nothing', 'user_id' => $user->id]); Tag::create(['tag' => 'TagTwo', 'tagMode' => 'nothing', 'user_id' => $user->id]); Tag::create(['tag' => 'TagThree', 'tagMode' => 'nothing', 'user_id' => $user->id]); }