Ejemplo n.º 1
0
 /**
  * Insert new Product into database
  *
  * @return Response Redirect
  */
 public function postCreate(ProductRequest $request)
 {
     $product = new Product();
     $product->fill($request->all());
     $product->user_id = \Sentinel::getUser()->id;
     if ($request->input('featured') == null) {
         $product->featured = false;
     }
     $product = $this->productRepository->createOrUpdate($product);
     if ($request->get('tag') != null && $request->get('tag') != '') {
         $tagInputs = explode(',', $request->get('tag'));
         foreach ($tagInputs as $tagName) {
             $tag = $this->tagRepository->findByName($tagName);
             if ($tag === null) {
                 $tag = new Tag();
                 $tag->name = $tagName;
                 $tag->user_id = \Sentinel::getUser()->id;
                 $tag = $this->tagRepository->createOrUpdate($tag);
             }
             $product->tags()->attach($tag->id);
         }
     }
     event(new AuditHandlerEvent('Product', 'created', $product->id));
     \Cache::forget('home_widget_featured');
     if ($request->get('submit') === 'save') {
         return redirect()->route('products.list')->with('success_msg', trans('notices.create_success_message'));
     } elseif ($request->get('submit') === 'apply') {
         return redirect()->route('products.edit', $product->id)->with('success_msg', trans('notices.create_success_message'));
     }
 }
Ejemplo n.º 2
0
 public function createSlug($name, $id)
 {
     $slug = Str::slug($name);
     $index = 1;
     $baseSlug = $slug;
     while (Product::whereSlug($slug)->where('id', '!=', $id)->count() > 0) {
         $slug = $baseSlug . '-' . $index++;
     }
     return $slug;
 }