public function update(ProductRequest $request, Tag $tag, $id) { $tagsProduto = $tag->criaTags($request->only('tags')['tags']); $produto = $this->product->find($id); $produto->update($request->all()); $produto->tags()->sync($tagsProduto); return redirect()->route('admin.products'); }
public function tag($id) { $categories = $this->category->all(); $tag = $this->tag->find($id); $products = $tag->products()->get(); //dd($products->get()); return view('store.tag', compact('categories', 'products', 'tag')); }
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); }
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; }
/** * [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); }
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; }
public function tag($id) { $categories = Category::all(); $tag = Tag::find($id); $products = $tag->products; return view('store.tag', compact('categories', 'products', 'tag')); }
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; }
public function tags($id) { $tag = Tag::find($id); if ($tag) { $categories = Category::all(); $products = $tag->products; $tag_name = $tag->name; return view('store.tags', compact('categories', 'tag_name', 'products')); } else { return redirect()->route('store.index'); } }
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); }
public function update(Requests\ProductRequest $request, $id) { $input = $request->all(); $tags_update = array_map('trim', explode(',', $input['tags'])); $array_update_tags = array(); foreach ($tags_update as $tag) { if (!empty($tag)) { if (!in_array($tag, Tag::lists('name')->toArray())) { Tag::create(['name' => $tag]); } array_push($array_update_tags, Tag::lists('id', 'name')->toArray()[$tag]); } } $this->productModel->find($id)->update($input); $this->productModel->find($id)->tags()->sync($array_update_tags); return redirect()->route('admin.products.index'); }
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); }
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; }
public function listProductsTags($id) { $categories = $this->category->all(); $tag = $this->tag->find($id); return view('store.products_tag', compact('tag', 'categories')); }
private function savetags($id, $tags) { // transforma objeto de csv para lista $tag_list = explode(',', $tags); $tag_list = array_map('trim', $tag_list); $tag_id_list = []; // atualiza tabela de tags foreach ($tag_list as $tag) { $tag = ltrim($tag); if ($tag != '') { $tag_reg = Tag::ofName($tag)->get(); if ($tag_reg->count() == 0) { $tag_reg = Tag::create(['name' => $tag]); $tag_id_list[] = $tag_reg->id; } else { $tag_id_list[] = $tag_reg[0]->id; } } } $product = $this->productsmodel->find($id); $product->tags()->sync($tag_id_list); }
public static function getProductsByTag($id) { return Tag::find($id)->products; }
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; }
function tags_to_array($string) { $tags = explode(',', $string); $result = []; foreach ($tags as $tag) { array_push($result, Tag::firstOrCreate(['name' => trim($tag)])->id); } return $result; }
/** * Run the database seeds. * * @return void */ public function run() { Tag::truncate(); //elimina i dati dal DB factory('CodeCommerce\\Tag', 10)->create(); }
/** * 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'); }
public function produtosPorTag($id) { $produto = Tag::find($id)->products; $categories = Category::all(); return view('store.produtos_por_tag', compact('produto', 'categories')); }
/** * 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'); }
public function listByTag($id) { $tag = Tag::find($id); $products = Product::getProductsByTag($id); return view('store.tag', compact('tag', 'products')); }
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; }
/** * 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 } }
public function run() { Tag::truncate(); factory(Tag::class, 20)->create(); }
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; }
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; }