/** * Update the specified resource in storage. * * Only owner and admin, editor can edit designer page. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $design = Design::find($id); if (empty($design)) { abort(404); } if ($request->user()->cannot('edit-design', $design)) { abort(403); } if ($request->input('lock')) { if ($design->lock()) { return; // 200 OK } else { abort(423); // 423 Locked } } $this->validate($request, ['image_id' => 'integer|exists:image,id', 'gallery_image_ids.*' => 'integer|exists:image,id', 'designer_id' => 'integer|exists:designer,id', 'user_id' => 'integer|exists:user,id', 'tag_ids.*' => 'integer|exists:tag,id', 'price' => 'numeric|between:0.01,999999.99', 'currency' => 'required_with:price|' . Currencies::validator(), 'webshop' => 'url|max:255', 'translations.*.name' => 'string|max:255']); if ($request->has('user_id')) { if ($request->user()->can('transfer-design', $design)) { $design->transfer($request->input('user_id')); } else { abort(403); } } $design->fill($request->all()); $design->updateEuroPrice(); $design->save(); if ($request->has('translations')) { foreach ($request->input('translations') as $locale => $texts) { if (!Languages::has($locale)) { continue; } $translation = DesignTranslation::where([['design_id', $design->id], ['locale', $locale]])->first(); if (!count($translation)) { $translation = new DesignTranslation(); $translation->design_id = $design->id; $translation->locale = $locale; } $translation->fill($texts); $translation->save(); } } }
public function updateEuroPrice() { if (!empty($this->price) && !empty($this->currency)) { $this->eur_price = Currencies::euro($this->price, $this->currency); } }