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')
+ Создание объекта недвижимости
+ Изменение объекта недвижимости
+
First Name | -Last Name | -ZIP | -Birthday | -Points | -Average | -Amount | +Фото | +ID | +Название объекта | +Координаты X | +Координаты Y | +Дата создания | +Действия |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gloria | -Reeves | -67439 | -10/18/1985 | -4 | -0.1 | -$50 | -|||||||
if (empty($area->foto_main)) {?>Нет фото} else {?>}?> | +{{ $area->id }} | +{{ $area->name_area }} | +{{ $area->coord_x }} | +{{ $area->coord_y }} | +{{ $area->created_at }} | ++ | +|||||||
- | +- | +- | +- | +- | +- | +- | +