cineflex/database/seeders/RoomSeeder.php

56 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class RoomSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
foreach (\App\Models\Cinema::all() as $cinema) {
$rooms = [
[
'room_name' => 'Room 1',
'room_rows' => 10,
'room_columns' => 10,
],
[
'room_name' => 'Room 2',
2023-02-02 08:17:38 +01:00
'room_rows' => 5,
'room_columns' => 5,
],
2023-02-02 08:17:38 +01:00
];
foreach ($rooms as $room) {
2023-02-02 08:17:38 +01:00
$this->command->info("Creating room {$room['room_name']} for cinema {$cinema->cinema_name}");
$r = new \App\Models\Room();
$r->room_name = $room['room_name'];
$r->room_rows = $room['room_rows'];
$r->room_columns = $room['room_columns'];
$r->user_id = 1;
$r->cinema_id = $cinema->cinema_id;
$r->save();
for ($row = 1; $row <= $r->room_rows; $row++) {
2023-02-02 08:17:38 +01:00
$this->command->info("Creating row {$row} for room {$r->room_name}");
for ($column = 1; $column <= $r->room_columns; $column++) {
$s = new \App\Models\Seat();
$s->seat_row = $row;
$s->seat_column = $column;
$s->room_id = $r->room_id;
$s->save();
}
}
}
}
}
}