This commit is contained in:
2026-01-08 19:37:31 +00:00
parent 62100c42b0
commit 82f1f37af6
2 changed files with 54 additions and 12 deletions

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::create('room_availability', function (Blueprint $table) { Schema::create('room_availabilities', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('room_type_id')->constrained()->onDelete('cascade'); $table->foreignId('room_type_id')->constrained()->onDelete('cascade');
$table->date('date'); $table->date('date');

View File

@@ -2,24 +2,66 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use App\Models\Admin;
use App\Models\Hotel;
use App\Models\RoomType;
use App\Models\RoomAvailability;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
use WithoutModelEvents;
/** /**
* Seed the application's database. * Run the database seeds.
*/ */
public function run(): void public function run(): void
{ {
// User::factory(10)->create(); // Создать админа
$admin = Admin::firstOrCreate([
'email' => 'admin@hotels.ru',
], [
'name' => 'Admin User',
'password' => Hash::make('password'),
]);
User::factory()->create([ // Создать отель
'name' => 'Test User', $hotel = Hotel::create([
'email' => 'test@example.com', 'name' => 'Grand Hotel',
'address' => '123 Main St',
]);
$roomType1 = RoomType::create([
'hotel_id' => $hotel->id,
'name' => 'Двухместный',
'capacity' => 2,
'base_price' => 5000,
]);
$roomType2 = RoomType::create([
'hotel_id' => $hotel->id,
'name' => 'Люкс',
'capacity' => 4,
'base_price' => 10000,
]);
$startDate = now()->startOfDay();
$endDate = now()->addDays(30)->startOfDay();
for ($date = $startDate; $date <= $endDate; $date->modify('+1 day')) {
RoomAvailability::create([
'room_type_id' => $roomType1->id,
'date' => $date->format('Y-m-d'),
'is_available' => true,
'price_override' => null,
]);
RoomAvailability::create([
'room_type_id' => $roomType2->id,
'date' => $date->format('Y-m-d'),
'is_available' => true,
'price_override' => null,
]); ]);
} }
}
} }