private function storeTag($inputTags, $id)
 {
     $tagsIDs = array_map(function ($tagName) {
         return Tag::firstOrCreate(['name' => $tagName])->id;
     }, array_filter($inputTags));
     $product = $this->productModel->find($id);
     $product->tags()->sync($tagsIDs);
 }
 /**
  * @param string $tags
  * @return array
  */
 private function getTagIds($tags)
 {
     $tags = array_filter(array_map('trim', explode(',', $tags)));
     $tagsIds = [];
     foreach ($tags as $eachTagName) {
         $tagsIds[] = Tag::firstOrCreate(['name' => $eachTagName])->id;
     }
     return $tagsIds;
 }
 private function storeTag($inputTags, $id)
 {
     $tag = new Tag();
     foreach ($inputTags as $key => $value) {
         $newTag = $tag->firstOrCreate(["name" => $value]);
         $idTags[] = $newTag->id;
     }
     $product = $this->productModel->find($id);
     $product->tags()->sync($idTags);
 }
 /**
  * [insere_tags description]
  * @param  [type] $alltags [description]
  * @param  [type] $id      [description]
  * @return [type]          [description]
  */
 public function insere_tags($alltags, $id)
 {
     $tagModel = new Tag();
     $product = $this->productModel->find($id);
     $tags = explode(',', $alltags);
     $tagsAdd = array();
     foreach ($tags as $newtags) {
         $tag = $tagModel->firstOrCreate(['name' => trim($newtags)]);
         $tagsAdd[] = $tag->id;
     }
     $product->tags()->sync($tagsAdd);
 }
Пример #5
0
 public function tagToArray($tags)
 {
     $tagBanco = new Tag();
     $tags = explode(',', $tags);
     $tags = array_map('trim', $tags);
     $tagCollection = [];
     foreach ($tags as $tag) {
         $t = $tagBanco->firstOrCreate(['name' => $tag]);
         array_push($tagCollection, $t->id);
     }
     return $tagCollection;
 }
Пример #6
0
 public function criaTags($tagsString)
 {
     $tags = explode(';', $tagsString);
     $tagsIds = array();
     foreach ($tags as $tag) {
         $tagObject = new Tag();
         $tagObject->name = $tag;
         //$tagsExistentes[] = $tagObject->firstOrCreate(['name' => $tag]);
         $tagsIds[] = $tagObject->firstOrCreate(['name' => trim($tag)])->id;
     }
     return $tagsIds;
 }
Пример #7
0
 private function syncTags($tagList, $id)
 {
     $syncTag = [];
     $tags = explode(',', str_replace(';', ',', $tagList));
     $tags = array_filter($tags);
     $tags = array_map('trim', $tags);
     $tags = array_map('strip_tags', $tags);
     $tags = array_map('strtolower', $tags);
     foreach ($tags as $tag) {
         $syncTag[] = $this->tag->firstOrCreate(['name' => $tag])->id;
     }
     $product = $this->product->find($id);
     $product->tags()->sync($syncTag);
 }
 private function storeTag($inputTags, $id)
 {
     /*
         $tag = new Tag();
         $countTags = count($inputTags);
         foreach ($inputTags as $key => $value) {
             $newTag = $tag->firstOrCreate(["name" => $value]);
             $idTags[] = $newTag->id;
         }
         $product = $this->produtoModel->find($id);
         $product->tags()->sync($idTags);
     */
     $tagsIDs = array_map(function ($tagName) {
         return Tag::firstOrCreate(['name' => $tagName])->id;
     }, array_filter($inputTags));
     $product = $this->produtoModel->find($id);
     $product->tags()->sync($tagsIDs);
 }
Пример #9
0
 private function addTags($product, $tags)
 {
     //Insert New Tags or get a id for existents tags:
     $idsTags = array();
     //Initiates array to get tag's ids
     $tags = strtolower($tags);
     //All tags to lower case!
     $tagsArray = explode(",", $tags);
     //Transform tags strings in array
     foreach ($tagsArray as $tag) {
         $tag = trim($tag);
         $newTag = Tag::firstOrCreate(['name' => $tag]);
         $idsTags[] = $newTag->id;
     }
     //Attach tags with array idsTags by Sinc():
     sort($idsTags);
     $product->tags()->sync($idsTags);
     return;
 }
 private function getTagsIds($tags)
 {
     // array_filter remove todos os CAMPOS em branco e mantém apenas campos que possuírem dados.
     // array_map passa uma função em todos os elementos do array, no caso é o trim para remover os ESPAÇOS.
     // CAMPOS em branco são esaços em branco dentr de uma única TAG(espaço branco entre letras de uma tag.
     // Ex: "   mundo ,casa, bola  ,amor, etc...
     // ESPAÇOS em branco são Tags sem nenhum caractere(espaço branco entre virgulas/tags).
     // Ex: mundo, ,bola,casa, ,etc,...
     $tagList = array_filter(array_map('trim', explode(',', $tags)));
     $tagsIds = [];
     foreach ($tagList as $tagName) {
         // $tagsIds vai receber um novo Id de uma tag.
         // utilizo o metodo firsOrCreate do Model Tag, passando o parametro name = $tagName
         // ele pesquisa no bd se exite uma tag com o nome $tagName. Se existir, ele pega a tag e o id dela e grava no array $tagsIds para
         // depois iserir no bd. Se não existir, ele vai criar uma nova tag com o nome $tagName, pegar o id dela e gravar no array tagsIds
         // para ser inserida no bd da mesma form.
         $tagsIds[] = Tag::firstOrCreate(['name' => $tagName])->id;
     }
     return $tagsIds;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update($id, Requests\ProductRequest $request)
 {
     $input = array_map('trim', $request->all());
     if ($input['recommend'] == "on") {
         $input['recommend'] = 1;
     } else {
         $input['recommend'] = 0;
     }
     if ($input['featured'] == "on") {
         $input['featured'] = 1;
     } else {
         $input['featured'] = 0;
     }
     $tags = trim($request->input('tag'));
     $tags = array_filter(explode(",", $tags));
     $tags = array_filter($tags, 'trim');
     $arrTags = array();
     foreach ($tags as $t) {
         $tagAtual = Tag::firstOrCreate(array('name' => trim($t)));
         array_push($arrTags, $tagAtual->id);
     }
     $product = $this->productModel->find($id);
     $arrTrim = array_map('trim', $arrTags);
     $product->tags()->sync($arrTrim);
     $product->update($input);
     return redirect()->route('product');
 }
Пример #12
0
 public function getTagsIds($tags)
 {
     $tagList = array_filter(array_map('trim', explode(',', $tags)));
     $tagsIDs = [];
     foreach ($tagList as $tagName) {
         $tagsIDs[] = Tag::firstOrCreate(['name' => $tagName])->id;
     }
     return $tagsIDs;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\ProductRequest $request, Tag $tagModel, $id)
 {
     $product = $this->product->find($id);
     $data = $request->all();
     $tags = explode(',', str_replace(', ', ',', $data['tags']));
     $relatedTags = [];
     $product->update($data);
     foreach ($tags as $tag) {
         $tag = ucfirst(strtolower($tag));
         $thisTag = $tagModel->firstOrCreate(['name' => $tag]);
         echo $tag;
         $relatedTags[] = $thisTag->id;
     }
     $product->tags()->sync($relatedTags);
     return redirect()->route('products.index');
 }
 function tags_to_array($string)
 {
     $tags = explode(',', $string);
     $result = [];
     foreach ($tags as $tag) {
         array_push($result, Tag::firstOrCreate(['name' => trim($tag)])->id);
     }
     return $result;
 }
 /**
  * armazena tags e retorna array com as ids das tags
  * @param array $tagNames
  * @return array tagIds
  */
 private function storeTags(array $tagNames, $productId)
 {
     if (count($tagNames > 0)) {
         foreach ($tagNames as $tagName) {
             $tag = Tag::firstOrCreate(array('name' => trim($tagName)));
             //cria se não existir
             $tagIds[] = $tag->id;
         }
         $product = $this->products->find($productId);
         $product->tags()->sync($tagIds);
         //só mantén relacionadas as atuais
     }
 }
 private function tagToArray($tags)
 {
     $tags = explode(",", $tags);
     $tags = array_map('trim', $tags);
     $tagCollection = [];
     foreach ($tags as $tag) {
         $t = Tag::firstOrCreate(['name' => $tag]);
         array_push($tagCollection, $t->id);
     }
     return $tagCollection;
 }
 private function storeTags($tagList)
 {
     $tags = array_map('trim', explode(',', $tagList));
     foreach ($tags as $tag) {
         if (!empty($tag)) {
             $id = Tag::firstOrCreate(['name' => $tag]);
             $tagId[] = $id->id;
         }
     }
     return $tagId;
 }