Blame view
app/Http/Controllers/Admin/HousesController.php
5.85 KB
3575d19ae Админка новости и... |
1 2 3 4 5 |
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; |
d82a28f22 Админка форматы и... |
6 |
use App\Http\Requests\HousesRequest; |
f399180fc Админка страница ... |
7 8 9 |
use App\Models\Area; use App\Models\format_area; use App\Models\foto_house; |
3575d19ae Админка новости и... |
10 |
use App\Models\House; |
f399180fc Админка страница ... |
11 |
use App\Models\type_area; |
3575d19ae Админка новости и... |
12 |
use Illuminate\Http\Request; |
f399180fc Админка страница ... |
13 14 |
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; |
3575d19ae Админка новости и... |
15 16 17 18 19 20 21 22 23 24 |
class HousesController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { |
d82a28f22 Админка форматы и... |
25 26 |
$houses = House::query()->orderByDesc('created_at')->orderByDesc('id')->paginate(25); return view('admin.houses.index', compact('houses')); |
3575d19ae Админка новости и... |
27 28 29 30 31 32 33 34 35 |
} /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { |
f399180fc Админка страница ... |
36 37 38 39 |
$type_areas = type_area::all(); $format_areas = format_area::all(); $areas = Area::all(); return view('admin.houses.create', compact('areas', 'format_areas', 'type_areas')); |
3575d19ae Админка новости и... |
40 41 42 43 44 45 46 47 |
} /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ |
d82a28f22 Админка форматы и... |
48 |
public function store(HousesRequest $request) |
3575d19ae Админка новости и... |
49 |
{ |
d82a28f22 Админка форматы и... |
50 |
$params = $request->all(); |
d82a28f22 Админка форматы и... |
51 52 53 54 55 56 57 58 59 60 |
if ($request->has('foto_main')) { $params['foto_main'] = $request->file('foto_main')->store('houses', 'public'); } if ($request->has('object_plan')) { $params['object_plan'] = $request->file('object_plan')->store('houses', 'public'); } if ($request->has('floor_plan')) { $params['floor_plan'] = $request->file('floor_plan')->store('houses', 'public'); } |
f399180fc Админка страница ... |
61 62 63 |
if ($request->has('present')) { $params['present'] = $request->file('present')->store('houses', 'public'); } |
d82a28f22 Админка форматы и... |
64 65 66 67 |
House::create($params); return redirect()->route('admin.houses.index'); |
3575d19ae Админка новости и... |
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
} /** * Display the specified resource. * * @param \App\Models\House $house * @return \Illuminate\Http\Response */ public function show(House $house) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\House $house * @return \Illuminate\Http\Response */ public function edit(House $house) { |
f399180fc Админка страница ... |
89 90 91 92 93 |
$type_areas = type_area::all(); $format_areas = format_area::all(); $areas = Area::all(); return view('admin.houses.edit', compact('areas', 'format_areas', 'type_areas', 'house')); |
3575d19ae Админка новости и... |
94 95 96 97 98 99 100 101 102 |
} /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\House $house * @return \Illuminate\Http\Response */ |
f399180fc Админка страница ... |
103 |
public function update(HousesRequest $request, House $house) |
3575d19ae Админка новости и... |
104 |
{ |
f399180fc Админка страница ... |
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
$params = $request->all(); if ($request->has('foto_main')) { Storage::delete($house->foto_main); $params['foto_main'] = $request->file('foto_main')->store('houses', 'public'); } if ($request->has('object_plan')) { Storage::delete($house->object_plan); $params['object_plan'] = $request->file('object_plan')->store('houses', 'public'); } if ($request->has('floor_plan')) { Storage::delete($house->floor_plan); $params['floor_plan'] = $request->file('floor_plan')->store('houses', 'public'); } if ($request->has('present')) { Storage::delete($house->present); $params['present'] = $request->file('present')->store('houses', 'public'); } $house->update($params); return redirect()->route('admin.houses.index'); } /** * Просмотр дополнительных картинок */ public function view_images(House $house) { return view('admin.houses.view_img', compact('house')); } /** * Добавление дополнительной картинки у офиса * @param House $house * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View */ public function add_images(House $house) { return view('admin.houses.add_img', compact('house')); } public function add_images_store(Request $request, House $house) { $rules = [ 'foto' => 'required|min:3|max:255', ]; $messages = [ 'required' => 'Укажите обязательное поле', ]; $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return redirect()->route('admin.view.images.houses', ['house' => $house->id]) ->withErrors($validator); } else { $images_house = new foto_house(); $images_house->house_id = $house->id; if ($request->has('foto')) { $images_house->foto = $request->file('foto')->store('houses', 'public'); } $images_house->save(); return redirect()->route('admin.view.images.houses', ['house' => $house->id]); } } public function del_images(House $house, $id) { if (!empty($id)) { $images_house = foto_house::find((int)$id); $images_house->delete(); } return redirect()->route('admin.view.images.houses', ['house' => $house->id]); |
3575d19ae Админка новости и... |
179 180 181 182 183 184 185 186 187 188 |
} /** * Remove the specified resource from storage. * * @param \App\Models\House $house * @return \Illuminate\Http\Response */ public function destroy(House $house) { |
f399180fc Админка страница ... |
189 190 191 192 193 |
if (!empty($house->foto_main)) { Storage::delete($house->foto_main); } $house->delete(); return redirect()->route('admin.houses.index'); |
3575d19ae Админка новости и... |
194 195 |
} } |