diff --git a/app/Http/Controllers/Admin/HotelController.php b/app/Http/Controllers/Admin/HotelController.php new file mode 100644 index 0000000..ce73f3b --- /dev/null +++ b/app/Http/Controllers/Admin/HotelController.php @@ -0,0 +1,77 @@ +view('admin/hotels/index', compact('hotels')); + } + + /** + * Показать форму создания отеля. + */ + public function create() + { + return view('admin.hotels.create'); + } + + /** + * Сохранить новый отель. + */ + public function store(Request $request) + { + $validated = $request->validate([ + 'name' => 'required|string|max:255', + 'address' => 'nullable|string', + 'phone' => 'nullable|string', + ]); + + Hotel::create($validated); + + return redirect()->route('admin.hotels.index')->with('success', 'Отель добавлен!'); + } + + /** + * Показать форму редактирования отеля. + */ + public function edit(Hotel $hotel) + { + return view('admin.hotels.edit', compact('hotel')); + } + + /** + * Обновить отель. + */ + public function update(Request $request, Hotel $hotel) + { + $validated = $request->validate([ + 'name' => 'required|string|max:255', + 'address' => 'nullable|string', + 'phone' => 'nullable|string', + ]); + + $hotel->update($validated); + + return redirect()->route('admin.hotels.index')->with('success', 'Отель обновлён!'); + } + + /** + * Удалить отель. + */ + public function destroy(Hotel $hotel) + { + $hotel->delete(); + + return redirect()->route('admin.hotels.index')->with('success', 'Отель удалён!'); + } +} diff --git a/app/Http/Controllers/HotelController.php b/app/Http/Controllers/HotelController.php index e20c76b..37468a4 100644 --- a/app/Http/Controllers/HotelController.php +++ b/app/Http/Controllers/HotelController.php @@ -10,7 +10,8 @@ class HotelController extends Controller { public function index() { - return Hotel::all(); + $hotels = Hotel::all(); + return view('admin.hotels.index', compact('hotels')); } public function store(Request $request) diff --git a/database/migrations/2025_12_28_230043_create_hotels_table.php b/database/migrations/2025_12_28_230043_create_hotels_table.php index f0c22bd..596d980 100644 --- a/database/migrations/2025_12_28_230043_create_hotels_table.php +++ b/database/migrations/2025_12_28_230043_create_hotels_table.php @@ -4,27 +4,21 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration +class CreateHotelsTable extends Migration { - /** - * Run the migrations. - */ - public function up(): void + public function up() { Schema::create('hotels', function (Blueprint $table) { $table->id(); - $table->string('name'); - $table->string('address'); - $table->text('description')->nullable(); + $table->string('name'); + $table->text('address')->nullable(); + $table->string('phone')->nullable(); $table->timestamps(); }); } - /** - * Reverse the migrations. - */ - public function down(): void + public function down() { Schema::dropIfExists('hotels'); } -}; +} \ No newline at end of file diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index a05ad84..794895b 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -17,7 +17,7 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // Создать админа + // Админ $admin = Admin::firstOrCreate([ 'email' => 'admin@hotels.ru', ], [ @@ -25,7 +25,7 @@ class DatabaseSeeder extends Seeder 'password' => Hash::make('password'), ]); - // Создать отель + // Отель $hotel = Hotel::create([ 'name' => 'Grand Hotel', 'address' => '123 Main St', diff --git a/resources/views/admin/hotels/create.blade.php b/resources/views/admin/hotels/create.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/admin/hotels/edit.blade.php b/resources/views/admin/hotels/edit.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/admin/hotels/index.blade.php b/resources/views/admin/hotels/index.blade.php new file mode 100644 index 0000000..4abb142 --- /dev/null +++ b/resources/views/admin/hotels/index.blade.php @@ -0,0 +1,45 @@ +@extends('admin.layout') + +@section('content') +
| Название | +Адрес | +Телефон | +Действия | +
|---|---|---|---|
| {{ $hotel->name }} | +{{ $hotel->address ?? '-' }} | +{{ $hotel->phone ?? '-' }} | ++ Редактировать + + | +