Ejemplo n.º 1
0
 public function display(Request $request, $store = null)
 {
     $stores = config('omnomcom.stores');
     if (array_key_exists($store, $stores)) {
         $storedata = $stores[$store];
         if (!in_array($request->ip(), $storedata->addresses) && (!Auth::check() || !Auth::user()->can($storedata->roles))) {
             abort(403);
         }
         $categories = [];
         foreach ($storedata->categories as $category) {
             $cat = ProductCategory::find($category);
             if ($cat) {
                 $prods = $cat->products;
                 $categories[] = (object) ['category' => $cat, 'products' => $prods];
             }
         }
         return view('omnomcom.store.show', ['categories' => $categories, 'store' => $storedata, 'storeslug' => $store]);
     } else {
         return view('omnomcom.store.pick', ['stores' => $stores]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $product = Product::findOrFail($id);
     $product->fill($request->except('image', 'product_categories'));
     $product->is_visible = $request->has('is_visible');
     $product->is_alcoholic = $request->has('is_alcoholic');
     $product->is_visible_when_no_stock = $request->has('is_visible_when_no_stock');
     if ($request->file('image')) {
         $file = new StorageEntry();
         $file->createFromFile($request->file('image'));
         $product->image()->associate($file);
     }
     $product->account()->associate(Account::findOrFail($request->input('account_id')));
     $categories = [];
     if ($request->has('product_categories') && count($request->input('product_categories')) > 0) {
         foreach ($request->input('product_categories') as $category) {
             $category = ProductCategory::find($category);
             if ($category != null) {
                 $categories[] = $category->id;
             }
         }
     }
     $product->categories()->sync($categories);
     $product->save();
     $request->session()->flash('flash_message', 'The product has been updated.');
     return Redirect::route('omnomcom::products::edit', ['id' => $product->id]);
 }