public function storeCustomRecord($parameters) { // check if there is id if ($this->request->has('id')) { $id = $this->request->input('id'); $idLang = $id; } else { $id = Article::max('id_355'); $id++; $idLang = null; } $article = Article::create(['id_355' => $id, 'lang_id_355' => $this->request->input('lang'), 'author_id_355' => $this->request->input('author'), 'section_id_355' => $this->request->input('section'), 'family_id_355' => $this->request->has('family') ? $this->request->input('family') : null, 'status_id_355' => $this->request->input('status'), 'publish_355' => $this->request->has('publish') ? \DateTime::createFromFormat(config('pulsar.datePattern') . ' H:i', $this->request->input('publish'))->getTimestamp() : (int) date('U'), 'publish_text_355' => $this->request->has('publish') ? $this->request->input('publish') : date(config('pulsar.datePattern') . ' H:i'), 'date_355' => $this->request->has('date') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('date'))->getTimestamp() : null, 'title_355' => $this->request->has('title') ? $this->request->input('title') : null, 'slug_355' => $this->request->has('slug') ? $this->request->input('slug') : null, 'link_355' => $this->request->has('link') ? $this->request->input('link') : null, 'blank_355' => $this->request->has('blank'), 'sorting_355' => $this->request->has('sorting') ? $this->request->input('sorting') : null, 'article_355' => $this->request->input('article'), 'data_lang_355' => Article::addLangDataRecord($this->request->input('lang'), $idLang), 'data_355' => null]); // get object with builder, to get every relations $article = Article::builder()->where('id_355', $article->id_355)->where('lang_id_355', $article->lang_id_355)->first(); // tags $tags = json_decode($this->request->input('jsonTags')); if (is_array($tags) && count($tags) > 0) { $idTags = []; foreach ($tags as $tag) { if ($tag->value === 'null') { $tagObj = Tag::create(['lang_id_358' => $this->request->input('lang'), 'name_358' => $tag->label]); $idTags[] = $tagObj->id_358; } else { $idTags[] = $tag->value; } } $article->getTags()->sync($idTags); } // set categories if (is_array($this->request->input('categories'))) { $article->getCategories()->sync($this->request->input('categories')); } // set attachments $attachments = json_decode($this->request->input('attachments')); AttachmentLibrary::storeAttachments($attachments, 'cms', 'cms-article', $id, $this->request->input('lang')); // set custom fields if ($article->field_group_id_351 !== null) { CustomFieldResultLibrary::storeCustomFieldResults($this->request, $article->field_group_id_351, 'cms-article-family', $article->id_355, $this->request->input('lang')); } }