コード例 #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id, Category $category, Tag $tag, Color $color)
 {
     // envio as categorias para a view products.create
     $categories = $category->lists('name', 'id');
     $product = $this->model->find($id);
     $tags = $tag->lists('name');
     $colors = $color->lists('name');
     return view('products.edit', compact('product', 'categories', 'tags', 'colors'));
 }
コード例 #2
0
 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');
 }