From 7c115bff1b6da3dd756680c7026e2086c20b26c3 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: Mon, 13 Mar 2023 12:38:16 +0700 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0=20-=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D1=8B=20=D0=BD=D0=B5=D0=B4=D0?= =?UTF-8?q?=B2=D0=B8=D0=B6=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Classes/RusDate.php | 3 +- app/Http/Controllers/Admin/AreaController.php | 48 +++++++++++---- app/Http/Controllers/AdminController.php | 2 - app/Http/Requests/AreasRequest.php | 40 ++++++++++++ app/Models/Area.php | 3 + .../2023_03_01_072712_create_areas_table.php | 12 ++-- resources/views/admin/area/create.blade.php | 25 ++++++++ resources/views/admin/area/edit.blade.php | 26 ++++++++ resources/views/admin/area/form.blade.php | 45 ++++++++++++++ resources/views/admin/area/index.blade.php | 64 ++++++++++++++------ resources/views/admin/area/view.blade.php | 48 +++++++++++++++ resources/views/admin/index.blade.php | 2 +- resources/views/auth/vefiry-message.blade.php | 23 +++++++ resources/views/layout/admin.blade.php | 61 ++++++++++++++++++- routes/web.php | 6 ++ 15 files changed, 366 insertions(+), 42 deletions(-) create mode 100644 app/Http/Requests/AreasRequest.php create mode 100644 resources/views/admin/area/create.blade.php create mode 100644 resources/views/admin/area/edit.blade.php create mode 100644 resources/views/admin/area/form.blade.php create mode 100644 resources/views/admin/area/view.blade.php create mode 100644 resources/views/auth/vefiry-message.blade.php diff --git a/app/Classes/RusDate.php b/app/Classes/RusDate.php index 217778e..5af75c6 100644 --- a/app/Classes/RusDate.php +++ b/app/Classes/RusDate.php @@ -68,7 +68,8 @@ class RusDate } public static function clear_items() { - unset($_COOKIE['favorite_house']); + if (!empty($_COOKIE['favorite_house'])) + unset($_COOKIE['favorite_house']); //print_r($_COOKIE['arr']); } } diff --git a/app/Http/Controllers/Admin/AreaController.php b/app/Http/Controllers/Admin/AreaController.php index 4719e50..abec8e4 100644 --- a/app/Http/Controllers/Admin/AreaController.php +++ b/app/Http/Controllers/Admin/AreaController.php @@ -3,8 +3,10 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Http\Requests\AreasRequest; use App\Models\Area; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; class AreaController extends Controller { @@ -21,12 +23,12 @@ class AreaController extends Controller /** * Show the form for creating a new resource. - * + * Форма создания объекта * @return \Illuminate\Http\Response */ public function create() { - // + return view('admin.area.create'); } @@ -40,53 +42,73 @@ class AreaController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ - public function store(Request $request) + public function store(AreasRequest $request) { - // + $params = $request->all(); + //unset($params['foto_main']); + + if ($request->has('foto_main')) { + $params['foto_main'] = $request->file('foto_main')->store('areas', 'public'); + } + + Area::create($params); + return redirect()->route('admin.area.index'); } /** * Display the specified resource. - * + * Просмотр объекта недвижимости * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function show(Area $area) { - // + return view('admin.area.view', compact('area')); } /** * Show the form for editing the specified resource. - * + * Форма редактирования объекта * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function edit(Area $area) { - // + return view('admin.area.edit', compact('area')); } /** * Update the specified resource in storage. - * + * Обновление-сохранение объекта недвижимости * @param \Illuminate\Http\Request $request * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ - public function update(Request $request, Area $area) + public function update(AreasRequest $request, Area $area) { - // + $params = $request->all(); + unset($params['foto_main']); + if ($request->has('foto_main')) { + Storage::delete($area->foto_main); + $params['foto_main'] = $request->file('foto_main')->store('areas', 'public'); + } + + $area->update($params); + return redirect()->route('admin.area.index'); } /** * Remove the specified resource from storage. - * + * Удаление объекта недвижимости * @param \App\Models\Area $area * @return \Illuminate\Http\Response */ public function destroy(Area $area) { - // + if (!empty($area->foto_main)) { + Storage::delete($area->foto_main); + } + $area->delete(); + return redirect()->route('admin.area.index'); } } diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 02cbc28..9b0ec4d 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -10,6 +10,4 @@ class AdminController extends Controller public function index() { return view('admin.index'); } - - // страница } diff --git a/app/Http/Requests/AreasRequest.php b/app/Http/Requests/AreasRequest.php new file mode 100644 index 0000000..ed31508 --- /dev/null +++ b/app/Http/Requests/AreasRequest.php @@ -0,0 +1,40 @@ + + */ + public function rules() + { + return [ + 'name_area' => 'required|min:3|max:255', + 'description' => 'required|min:5', + ]; + } + + public function messages() { + return [ + 'required' => 'Поле :attribute обязательно для ввода', + 'min' => 'Поле :attribute должно иметь минимум :min символов', + 'max' => 'Поле :attribute должно содержать не более :max символов' + ]; + } + +} diff --git a/app/Models/Area.php b/app/Models/Area.php index e5a8cd2..f2abe0d 100644 --- a/app/Models/Area.php +++ b/app/Models/Area.php @@ -9,6 +9,9 @@ class Area extends Model { use HasFactory; + protected $fillable = ['name_area', 'description', 'foto_main', 'coord_x', 'coord_y']; + + /* * Связь Объектов недвижимости с офисами */ diff --git a/database/migrations/2023_03_01_072712_create_areas_table.php b/database/migrations/2023_03_01_072712_create_areas_table.php index c61e4ce..6d7c567 100644 --- a/database/migrations/2023_03_01_072712_create_areas_table.php +++ b/database/migrations/2023_03_01_072712_create_areas_table.php @@ -15,13 +15,13 @@ return new class extends Migration { Schema::create('areas', function (Blueprint $table) { $table->id(); - $table->string('name_area', 255); - $table->string('slug', 255)->unique(); - $table->text('description'); + $table->string('name_area', 255)->nullable(); + $table->string('slug', 255)->unique()->nullable(); + $table->text('description')->nullable(); $table->string('map_coord')->default(''); - $table->float('coord_x')->default(0.0); - $table->float('coord_y')->default(0.0); - $table->string('foto_main', 255); + $table->integer('coord_x')->default(0); + $table->integer('coord_y')->default(0); + $table->string('foto_main', 255)->nullable(); $table->timestamps(); }); } diff --git a/resources/views/admin/area/create.blade.php b/resources/views/admin/area/create.blade.php new file mode 100644 index 0000000..7b4af9d --- /dev/null +++ b/resources/views/admin/area/create.blade.php @@ -0,0 +1,25 @@ +@extends('layout.admin', ['title' => 'Создание нового объекта']) + +@section('content') +
+
+
+ +

Создание объекта недвижимости

+
+
+
+
+
+ @include('admin.area.form') +
+
+
+
+@endsection diff --git a/resources/views/admin/area/edit.blade.php b/resources/views/admin/area/edit.blade.php new file mode 100644 index 0000000..e4b0716 --- /dev/null +++ b/resources/views/admin/area/edit.blade.php @@ -0,0 +1,26 @@ +@extends('layout.admin', ['title' => 'Изменение объекта']) + +@section('content') +
+
+
+ +

Изменение объекта недвижимости

+
+
+
+
+
+ @include('admin.area.form') +
+
+
+
+@endsection + diff --git a/resources/views/admin/area/form.blade.php b/resources/views/admin/area/form.blade.php new file mode 100644 index 0000000..71f64df --- /dev/null +++ b/resources/views/admin/area/form.blade.php @@ -0,0 +1,45 @@ +@csrf + +@isset($area) + @method('PUT') +@endisset + + +@error('name_area') +
{{ $message }}
+@enderror +
+ + +@error('description') +
{{ $message }}
+@enderror +
+ + +
+ + +
+ + + + + +@isset($area->foto_main) +
+ + + +
+@endisset +

+ + + diff --git a/resources/views/admin/area/index.blade.php b/resources/views/admin/area/index.blade.php index e4f8420..b23e39f 100644 --- a/resources/views/admin/area/index.blade.php +++ b/resources/views/admin/area/index.blade.php @@ -15,32 +15,60 @@
+ + Создать объект +

- - - - - - - + + + + + + + - - - - - - - - - - ... + @if ($areas->count()) + @foreach($areas as $area) + + + + + + + + + + @endforeach + @else + + + + + + + + + + @endif +
First NameLast NameZIPBirthdayPointsAverageAmountФотоIDНазвание объектаКоординаты XКоординаты YДата созданияДействия
GloriaReeves6743910/18/198540.1$50
foto_main)) {?>Нет фото{{ $area->id }}{{ $area->name_area }}{{ $area->coord_x }}{{ $area->coord_y }}{{ $area->created_at }}
+ + Просмотр + | + + Редактировать + | + @csrf + @method('DELETE') + +
+
-------
- + {{ $areas->onEachSide(1)->links('catalogs.paginate') }}
diff --git a/resources/views/admin/area/view.blade.php b/resources/views/admin/area/view.blade.php new file mode 100644 index 0000000..5d0217c --- /dev/null +++ b/resources/views/admin/area/view.blade.php @@ -0,0 +1,48 @@ +@extends('layout.admin', ['title' => 'Просмотр объекта']) + +@section('content') +
+
+
+ +

Просмотр объекта недвижимости

+
+
+
+
+
+

+ +
+

+ +
+

+ +
+

+ + +
+ @isset($area->foto_main) +
+ +
+ @endisset +
+ Вернуться к объектам +
+
+
+@endsection + diff --git a/resources/views/admin/index.blade.php b/resources/views/admin/index.blade.php index 5995818..333ed9c 100644 --- a/resources/views/admin/index.blade.php +++ b/resources/views/admin/index.blade.php @@ -19,7 +19,7 @@

Меню

diff --git a/resources/views/auth/vefiry-message.blade.php b/resources/views/auth/vefiry-message.blade.php new file mode 100644 index 0000000..8232b27 --- /dev/null +++ b/resources/views/auth/vefiry-message.blade.php @@ -0,0 +1,23 @@ +@extends('layout.site', ['title' => 'Неудачный вход в личный кабинет']) + +@section('content') +
+
+
+ + + +
+
+
+@endsection diff --git a/resources/views/layout/admin.blade.php b/resources/views/layout/admin.blade.php index 20e91c5..b3b0c58 100644 --- a/resources/views/layout/admin.blade.php +++ b/resources/views/layout/admin.blade.php @@ -15,6 +15,65 @@ +
@@ -24,7 +83,7 @@