/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $spaceship = Spaceships::findOrFail($id); // Split carousel string $carousel = explode(';', $spaceship->carousel); // Real or Not $spaceship->real = $spaceship->real ? 'Да' : 'Нет'; $meta_title = $spaceship->meta_title; $meta_desc = $spaceship->meta_desc; return view('spaceships.show', compact('spaceship', 'carousel', 'meta_title', 'meta_desc')); }
public function search(Request $request) { $name = $request->input('name'); if (!is_null($name)) { $spaceships = Spaceships::select('id', 'name')->where('name', 'LIKE', '%' . $name . '%')->paginate(10); // if request is similar redirect to page of spaceship foreach ($spaceships as $value) { if ($name === $value->name) { return redirect('spaceships/' . $value->id); } } } else { $spaceships = false; } $meta_title = 'Поиск по сайту'; $meta_desc = 'Найти космический корабль по названию'; return view('pages.search', compact('spaceships', 'meta_title', 'meta_desc')); }
/** * Delete carousel image * @param $id * @param $name * @return mixed */ public function deleteCarouselImage($id, $name) { $carousel = Spaceships::where('id', $id)->pluck('carousel'); $carousel_arr = explode(';', $carousel); foreach ($carousel_arr as $key => $image) { // Delete from arr if ($name === $image) { array_splice($carousel_arr, $key, 1); // Delete file File::delete($this->destinationPath . $image); } } $carousel = implode(';', $carousel_arr); // Add to db Spaceships::where('id', $id)->update(['carousel' => $carousel]); return redirect()->back(); }