public function updatePlace(Request $request, $id) { $Place = Place::find($id); $Place->title = $request->input('title'); $Place->author = $request->input('author'); $Place->isbn = $request->input('isbn'); $Place->save(); return response()->json($Place); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Place $place) { $exist = Place::find($place)->exists(); if ($exist) { return response()->json(true); } else { return response()->json(false); } }
/** * 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'])); } } }
public function toggleVisibility($id) { $place = Place::find($id); $place->public = !$place->public; $place->save(); return redirect()->back(); }
public function getPlaceAttribute() { return Place::find($this->place_id); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { if (Gate::denies('place.delete')) { return view(config('app.template') . '.error.403'); } $place = Place::find($id); if ($place && $place->update(['active' => 0])) { return redirect()->back()->with('succcess', 'Sukses hapus data ' . $place->nama . '.'); } return redirect()->back()->withErrors(['failed' => 'Gagal hapus data tempat pelanggan.']); }