From f399180fcf731cdf107edd25bddaefb2aed7306f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Wed, 15 Mar 2023 20:50:25 +0700 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B0=20=D0=BE=D1=84=D0=B8=D1?= =?UTF-8?q?=81=D1=8B=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D1=81=D0=BE=D0=BF=D1=83?= =?UTF-8?q?=D1=82=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B5=D0=B5=20=D0=B8=D0?= =?UTF-8?q?=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/HousesController.php | 105 +++- app/Http/Requests/HousesRequest.php | 48 +- app/Models/House.php | 10 + .../2023_03_01_073202_create_houses_table.php | 2 +- database/seeders/HousesTableSeeder.php | 18 +- resources/views/admin/houses/add_img.blade.php | 31 ++ resources/views/admin/houses/create.blade.php | 25 + resources/views/admin/houses/edit.blade.php | 25 + resources/views/admin/houses/form.blade.php | 533 ++++++++++++++++++++ resources/views/admin/houses/index.blade.php | 4 + resources/views/admin/houses/view_img.blade.php | 53 ++ routes/web.php | 12 + 12 files changed, 848 insertions(+), 18 deletions(-) create mode 100644 resources/views/admin/houses/add_img.blade.php create mode 100644 resources/views/admin/houses/view_img.blade.php diff --git a/app/Http/Controllers/Admin/HousesController.php b/app/Http/Controllers/Admin/HousesController.php index 675b41b..413571c 100644 --- a/app/Http/Controllers/Admin/HousesController.php +++ b/app/Http/Controllers/Admin/HousesController.php @@ -4,8 +4,14 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\HousesRequest; +use App\Models\Area; +use App\Models\format_area; +use App\Models\foto_house; use App\Models\House; +use App\Models\type_area; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Validator; class HousesController extends Controller { @@ -28,7 +34,10 @@ class HousesController extends Controller */ public function create() { - return view('admin.houses.create'); + $type_areas = type_area::all(); + $format_areas = format_area::all(); + $areas = Area::all(); + return view('admin.houses.create', compact('areas', 'format_areas', 'type_areas')); } /** @@ -40,7 +49,6 @@ class HousesController extends Controller public function store(HousesRequest $request) { $params = $request->all(); - //unset($params['foto_main']); if ($request->has('foto_main')) { $params['foto_main'] = $request->file('foto_main')->store('houses', 'public'); @@ -51,6 +59,9 @@ class HousesController extends Controller if ($request->has('floor_plan')) { $params['floor_plan'] = $request->file('floor_plan')->store('houses', 'public'); } + if ($request->has('present')) { + $params['present'] = $request->file('present')->store('houses', 'public'); + } House::create($params); @@ -76,7 +87,12 @@ class HousesController extends Controller */ public function edit(House $house) { - // + $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')); + } /** @@ -86,9 +102,82 @@ class HousesController extends Controller * @param \App\Models\House $house * @return \Illuminate\Http\Response */ - public function update(Request $request, House $house) + public function update(HousesRequest $request, House $house) { - // + $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]); } /** @@ -99,6 +188,10 @@ class HousesController extends Controller */ public function destroy(House $house) { - // + if (!empty($house->foto_main)) { + Storage::delete($house->foto_main); + } + $house->delete(); + return redirect()->route('admin.houses.index'); } } diff --git a/app/Http/Requests/HousesRequest.php b/app/Http/Requests/HousesRequest.php index 6f2e897..3695875 100644 --- a/app/Http/Requests/HousesRequest.php +++ b/app/Http/Requests/HousesRequest.php @@ -13,7 +13,7 @@ class HousesRequest extends FormRequest */ public function authorize() { - return false; + return true; } /** @@ -21,10 +21,54 @@ class HousesRequest extends FormRequest * * @return array */ + /* ['area_id', 'type_area_id', 'format_area_id', 'metro', 'color_metro', 'foto_main', + 'address', 'okrug', 'articul_area', 'format_house', 'floor', 'description_metro', + 'floor_bild', 'renter', 'uploading_area', 'electric_power', 'travel_card', + 'passing_place', 'separate_input', 'shop_windows', 'place_advertising', 'windows', + 'hood', 'central_heating', 'opening_hours', 'finishing', 'parking', 'price', 'rent_in_year', + 'rent_in_month', 'scheme_deal', 'present', 'object_plan', 'floor_plan', 'description_house', + 'map_coord', 'title', 'area', 'best', 'sos_obj', 'type_plan', 'description_2', + 'price_m2']; + */ public function rules() { return [ - // + 'title' => [ + 'required', + 'min:3', + 'max:100', + ], + 'address' => [ + 'required', + 'min:3', + 'max:100', + ], + 'price' => [ + 'required', + 'min:1', + 'max:100', + ], + 'foto_main' => [ + 'mimes:jpeg,jpg,png', + 'max:10000' + ], ]; } + + public function messages() { + return [ + 'required' => 'Поле «:attribute» обязательно для заполнения', + 'unique' => 'Такое значение поля «:attribute» уже используется', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + 'mimes' => 'Файл «:attribute» должен иметь формат :values', + ]; + + } } diff --git a/app/Models/House.php b/app/Models/House.php index 7c6c22f..1683dc6 100644 --- a/app/Models/House.php +++ b/app/Models/House.php @@ -9,6 +9,16 @@ class House extends Model { use HasFactory; + protected $fillable = ['area_id', 'type_area_id', 'format_area_id', 'metro', 'color_metro', 'foto_main', + 'address', 'okrug', 'articul_area', 'format_house', 'floor', 'description_metro', + 'floor_bild', 'renter', 'uploading_area', 'electric_power', 'travel_card', + 'passing_place', 'separate_input', 'shop_windows', 'place_advertising', 'windows', + 'hood', 'central_heating', 'opening_hours', 'finishing', 'parking', 'price', 'rent_in_year', + 'rent_in_month', 'scheme_deal', 'present', 'object_plan', 'floor_plan', 'description_house', + 'map_coord', 'title', 'area', 'best', 'sos_obj', 'type_plan', 'description_2', + 'price_m2']; + + /* * Связь таблицы ТИП НЕДВИЖИМОСТИ с таблицей ОФИСЫ */ diff --git a/database/migrations/2023_03_01_073202_create_houses_table.php b/database/migrations/2023_03_01_073202_create_houses_table.php index 196ed42..bc60a6f 100644 --- a/database/migrations/2023_03_01_073202_create_houses_table.php +++ b/database/migrations/2023_03_01_073202_create_houses_table.php @@ -19,7 +19,7 @@ return new class extends Migration $table->integer('type_area_id'); $table->integer('format_area_id'); $table->string('title', 255)->default(''); - $table->string('slug', 255)->default(''); + //$table->string('slug', 255)->default(''); $table->string('metro', 255)->default(''); $table->string('color_metro', 255)->default(''); $table->string('foto_main', 255)->default(''); diff --git a/database/seeders/HousesTableSeeder.php b/database/seeders/HousesTableSeeder.php index bc67cd3..7896cea 100644 --- a/database/seeders/HousesTableSeeder.php +++ b/database/seeders/HousesTableSeeder.php @@ -19,7 +19,7 @@ class HousesTableSeeder extends Seeder $data = [ /*1 */[ 'title' => 'Индустриальная недвижимость1', - 'slug' => 'Individual_nedvijimost1', + //'slug' => 'Individual_nedvijimost1', 'area_id' => 1, 'area' => 26, 'type_area_id' => 1, @@ -40,7 +40,7 @@ class HousesTableSeeder extends Seeder ], /*2*/[ 'title' => 'Индустриальная недвижимость2', - 'slug' => 'Individual_nedvijimost2', + //'slug' => 'Individual_nedvijimost2', 'area_id' => 1, 'area' => 18, 'type_area_id' => 2, @@ -61,7 +61,7 @@ class HousesTableSeeder extends Seeder ], /*3*/[ 'title' => 'Индустриальная недвижимость3', - 'slug' => 'Individual_nedvijimost3', + //'slug' => 'Individual_nedvijimost3', 'area_id' => 1, 'area' => 37, 'type_area_id' => 2, @@ -83,7 +83,7 @@ class HousesTableSeeder extends Seeder /*4*/[ 'title' => 'Офис1', - 'slug' => 'ofic1', + //'slug' => 'ofic1', 'area_id' => 1, 'area' => 34, 'type_area_id' => 2, @@ -106,7 +106,7 @@ class HousesTableSeeder extends Seeder /*5*/ [ 'title' => 'Индустриальная недвижимость5', - 'slug' => 'Individual_nedvijimost5', + // 'slug' => 'Individual_nedvijimost5', 'area_id' => 2, 'area' => 16, 'type_area_id' => 2, @@ -129,7 +129,7 @@ class HousesTableSeeder extends Seeder /*6*/ [ 'title' => 'Индустриальная недвижимость6', - 'slug' => 'Individual_nedvijimost6', + //'slug' => 'Individual_nedvijimost6', 'area_id' => 2, 'area' => 30, 'type_area_id' => 3, @@ -152,7 +152,7 @@ class HousesTableSeeder extends Seeder /*7*/ [ 'title' => 'Офис7', - 'slug' => 'Individual_nedvijimost7', + //'slug' => 'Individual_nedvijimost7', 'area_id' => 2, 'area' => 25, 'type_area_id' => 1, @@ -175,7 +175,7 @@ class HousesTableSeeder extends Seeder /*8*/ [ 'title' => 'Индустриальная недвижимость8', - 'slug' => 'Individual_nedvijimost8', + //'slug' => 'Individual_nedvijimost8', 'area_id' => 2, 'area' => 20, 'type_area_id' => 3, @@ -199,7 +199,7 @@ class HousesTableSeeder extends Seeder foreach ($data as $item) { $albom = new House(); $albom->title = $item['title']; - $albom->slug = $item['slug']; + //$albom->slug = $item['slug']; $albom->area_id = $item['area_id']; $albom->area = $item['area']; $albom->type_area_id = $item['type_area_id']; diff --git a/resources/views/admin/houses/add_img.blade.php b/resources/views/admin/houses/add_img.blade.php new file mode 100644 index 0000000..3450be0 --- /dev/null +++ b/resources/views/admin/houses/add_img.blade.php @@ -0,0 +1,31 @@ +@extends('layout.admin', ['title' => 'Добавление картинки офиса']) + +@section('content') +
+
+
+ +

Добавление доп.картинки офиса

+
+
+
+
+

Название: {{ $house->title }} ID: ({{ $house->id }})

+
+ @csrf + + + +

+ +
+
+
+
+@endsection diff --git a/resources/views/admin/houses/create.blade.php b/resources/views/admin/houses/create.blade.php index e69de29..c85b631 100644 --- a/resources/views/admin/houses/create.blade.php +++ b/resources/views/admin/houses/create.blade.php @@ -0,0 +1,25 @@ +@extends('layout.admin', ['title' => 'Создание офиса']) + +@section('content') +
+
+
+ +

Создание офиса

+
+
+
+
+
+ @include('admin.houses.form') +
+
+
+
+@endsection diff --git a/resources/views/admin/houses/edit.blade.php b/resources/views/admin/houses/edit.blade.php index e69de29..deb03d5 100644 --- a/resources/views/admin/houses/edit.blade.php +++ b/resources/views/admin/houses/edit.blade.php @@ -0,0 +1,25 @@ +@extends('layout.admin', ['title' => 'Редактирование офиса']) + +@section('content') +
+
+
+ +

Редактирование офиса

+
+
+
+
+
+ @include('admin.houses.form') +
+
+
+
+@endsection diff --git a/resources/views/admin/houses/form.blade.php b/resources/views/admin/houses/form.blade.php index e69de29..5fab029 100644 --- a/resources/views/admin/houses/form.blade.php +++ b/resources/views/admin/houses/form.blade.php @@ -0,0 +1,533 @@ +@csrf + +@isset($house) + @method('PUT') +@endisset + +
+@error('title') +
{{ $message }}
+@enderror +

+ +
+@error('best') +
{{ $message }}
+@enderror +

+ +
+@error('area_id') +
{{ $message }}
+@enderror +

+ +
+@error('type_area_id') +
{{ $message }}
+@enderror +

+ +
+@error('format_area_id') +
{{ $message }}
+@enderror +

+ +
+@error('metro') +
{{ $message }}
+@enderror +

+ +
+@error('description_metro') +
{{ $message }}
+@enderror +

+ +
+@error('address') +
{{ $message }}
+@enderror +

+ +
+@error('okrug') +
{{ $message }}
+@enderror +

+ +
+
+ +@isset($house->foto_main) +
+ + + +
+@endisset +
+ +
+@error('articul_area') +
{{ $message }}
+@enderror +

+ +
+@error('format_house') +
{{ $message }}
+@enderror +

+ +
+@error('area') +
{{ $message }}
+@enderror +

+ +
+@error('floor') +
{{ $message }}
+@enderror +

+ +
+@error('floor_bild') +
{{ $message }}
+@enderror +

+ +
+@error('renter') +
{{ $message }}
+@enderror +

+ +
+@error('price') +
{{ $message }}
+@enderror +

+ +
+@error('price_m2') +
{{ $message }}
+@enderror +

+ +
+@error('rent_in_year') +
{{ $message }}
+@enderror +

+ +
+@error('description_house') +
{{ $message }}
+@enderror +

+ +
+ + +@isset($house->object_plan) +
+ +
+@endisset +

+ +
+ + +@isset($house->floor_plan) +
+ +
+@endisset +

+ +
+ + +@isset($house->present) + +@endisset +

+ +
+@error('unloading_area') +
{{ $message }}
+@enderror +

+ +
+@error('electric_power') +
{{ $message }}
+@enderror +

+ +
+@error('travel_card') +
{{ $message }}
+@enderror +

+ +
+@error('passing_place') +
{{ $message }}
+@enderror +

+ +
+@error('separate_input') +
{{ $message }}
+@enderror +

+ +
+@error('shop_windows') +
{{ $message }}
+@enderror +

+ +
+@error('place_advertising') +
{{ $message }}
+@enderror +

+ +
+@error('windows') +
{{ $message }}
+@enderror +

+ +
+@error('hood') +
{{ $message }}
+@enderror +

+ +
+@error('central_heating') +
{{ $message }}
+@enderror +

+ +
+@error('opening_hours') +
{{ $message }}
+@enderror +

+ +
+@error('finishing') +
{{ $message }}
+@enderror +

+ +
+@error('parking') +
{{ $message }}
+@enderror +

+ +
+@error('scheme_deal') +
{{ $message }}
+@enderror +

+ +
+

+ +
+@error('sos_obj') +
{{ $message }}
+@enderror +

+ +
+@error('type_plan') +
{{ $message }}
+@enderror +

+ +
+@error('description_2') +
{{ $message }}
+@enderror +

+ +
+ + + diff --git a/resources/views/admin/houses/index.blade.php b/resources/views/admin/houses/index.blade.php index 929d119..b2e09d1 100644 --- a/resources/views/admin/houses/index.blade.php +++ b/resources/views/admin/houses/index.blade.php @@ -47,6 +47,10 @@ Редактировать | + + Доп.картинки + | + @csrf @method('DELETE') diff --git a/resources/views/admin/houses/view_img.blade.php b/resources/views/admin/houses/view_img.blade.php new file mode 100644 index 0000000..c4c4a1f --- /dev/null +++ b/resources/views/admin/houses/view_img.blade.php @@ -0,0 +1,53 @@ +@extends('layout.admin', ['title' => 'Дополнительные картинки офиса']) + +@section('content') +
+
+
+ +

Дополнительные картинки офиса

+
+
+
+
+

ID: {{$house->id}} Название офиса: {{$house->title}}



+

Дополнительные картинки


+ Добавить картинку в галерею

+ + + + + + + + + + + @if ($house->fotohouse->count()) + @foreach($house->fotohouse as $img) + + + + + + @endforeach + @else + + + + + + @endif + +
IDФотоДействия
id?>Удалить
---
+
+
+
+@endsection + diff --git a/routes/web.php b/routes/web.php index d178e8b..c1c31e7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -193,4 +193,16 @@ Route::group([ */ Route::resource('houses', HousesController::class, ['except' => ['show']]); + // просмотр дополнительных картинок офиса + Route::get('houses/{house}/images', [HousesController::class, 'view_images'])->name('view.images.houses'); + + // форма добавление дополнительной картинки офиса + Route::get('houses/{house}/add/images', [HousesController::class, 'add_images'])->name('add.images.houses'); + + // добавление дополнительной картинки офиса + Route::post('houses/{house}/add/images', [HousesController::class, 'add_images_store'])->name('add.image.post.houses'); + + // удаление дополнительной картинки офиса + Route::get('houses/{house}/del/{id}/images', [HousesController::class, 'del_images'])->name('del.images.houses'); + }); -- 1.7.10.4