seeder
This commit is contained in:
@@ -11,7 +11,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('room_availability', function (Blueprint $table) {
|
||||
Schema::create('room_availabilities', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('room_type_id')->constrained()->onDelete('cascade');
|
||||
$table->date('date');
|
||||
|
||||
@@ -2,24 +2,66 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
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
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
// Создать админа
|
||||
$admin = Admin::firstOrCreate([
|
||||
'email' => 'admin@hotels.ru',
|
||||
], [
|
||||
'name' => 'Admin User',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
// Создать отель
|
||||
$hotel = Hotel::create([
|
||||
'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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user