/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $story = Story::find($id); if (empty($story)) { abort(404); } if ($request->user()->cannot('edit-story', $story)) { abort(403); } if ($request->input('lock')) { if ($story->lock()) { return; // 200 OK } else { abort(423); // 423 Locked } } $this->validate($request, ['image_id' => 'integer|exists:image,id', 'user_id' => 'integer|exists:user,id', 'tag_ids.*' => 'integer|exists:tag,id', 'translations' => 'array', 'translations.*.title' => 'string|max:255', 'translations.*.content' => 'string']); $story->update(app_array_filter($request->all(), ['image_id', 'tag_ids'])); // TODO transfer story page to another user... if ($request->has('translations')) { foreach ($request->input('translations') as $locale => $texts) { if (!Languages::has($locale)) { continue; } $translation = StoryTranslation::firstOrCreate(['story_id' => $id, 'locale' => $locale]); $translation->update(app_array_filter($texts, ['title', 'content'])); } } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $place = Place::find($id); if (empty($place)) { abort(404); } if ($request->user()->cannot('edit-place', $place)) { abort(403); } if ($request->input('lock')) { if ($place->lock()) { return; // 200 OK } else { abort(423); // 423 Locked } } // Validate data $this->validate($request, ['type' => 'string|in:' . implode(',', Place::types()), 'image_id' => 'integer|exists:image,id', 'gallery_image_ids.*' => 'integer|exists:image,id', 'city_id' => 'integer|exists:city,id', 'address' => 'string|max:255', 'latitude' => 'numeric', 'longitude' => 'numeric', 'tag_ids.*' => 'integer|exists:tag,id', 'email' => 'email|max:255', 'phone' => 'string|max:255', 'website' => 'url|max:255', 'facebook' => 'url|max:255', 'translations.*.name' => 'string|max:255', 'translations.*.content' => 'string']); if ($request->has('user_id')) { if ($request->user()->can('transfer-place', $place)) { $place->transfer($request->input('user_id')); } else { abort(403); } } $place->fill($request->all()); $place->save(); if ($request->has('translations')) { foreach ($request->input('translations') as $locale => $texts) { if (!Languages::has($locale)) { continue; } $translation = PlaceTranslation::firstOrCreate(['place_id' => $id, 'locale' => $locale]); $translation->update(app_array_filter($texts, ['name', 'content'])); } } }
/** * 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) { $designer = Designer::find($id); if (empty($designer)) { abort(404); } if ($request->user()->cannot('edit-designer', $designer)) { abort(403); } if ($request->input('lock')) { if ($designer->lock()) { return; // 200 OK } else { abort(423); // 423 Locked } } $this->validate($request, ['image_id' => 'integer|exists:image,id', 'logo_id' => 'integer|exists:image,id', 'gallery_image_ids.*' => 'integer|exists:image,id', 'city_id' => 'integer|exists:city,id', 'user_id' => 'integer|exists:user,id', 'tag_ids.*' => 'integer|exists:tag,id', 'email' => 'email|max:255', 'website' => 'url|max:255', 'facebook' => 'url|max:255', 'instagram' => 'url|max:255', 'pinterest' => 'url|max:255', 'youtube' => 'url|max:255', 'vimeo' => 'url|max:255', 'translations.*.name' => 'string|max:255', 'translations.*.tagline' => 'string|max:255', 'translations.*.content' => 'string']); if ($request->has('user_id')) { if ($request->user()->can('transfer-designer', $designer)) { $designer->transfer($request->input('user_id')); } else { abort(403); } } $designer->fill($request->all()); $designer->save(); if ($request->has('translations')) { foreach ($request->input('translations') as $locale => $texts) { if (!Languages::has($locale)) { continue; } $translation = DesignerTranslation::firstOrCreate(['designer_id' => $id, 'locale' => $locale]); $translation->update(app_array_filter($texts, ['name', 'tagline', 'content'])); } } }