cineflex/database/seeders/ShowingSeeder.php

89 lines
2.9 KiB
PHP
Raw Normal View History

<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class ShowingSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $showStart = <current time + 5days>;
$showStart = new \DateTime();
$showStart->add(new \DateInterval('P5D'));
foreach (\App\Models\Room::all() as $room) {
$showings = [
[
'showing_start' => $showStart->format('Y-m-d H:i:s'),
'showing_end' => $showStart->add(new \DateInterval('PT2H'))->format('Y-m-d H:i:s'),
'movie_id' => 1,
'room_id' => $room->room_id,
2023-02-02 08:17:38 +01:00
'pricings' => [
[
'price' => 10,
'price_type' => 'adult',
],
[
'price' => 8,
'price_type' => 'senior',
],
[
'price' => 2.5,
'price_type' => 'child',
],
],
],
[
'showing_start' => $showStart->add(new \DateInterval('PT2H'))->format('Y-m-d H:i:s'),
'showing_end' => $showStart->add(new \DateInterval('PT2H'))->format('Y-m-d H:i:s'),
'movie_id' => 2,
'room_id' => $room->room_id,
2023-02-02 08:17:38 +01:00
'pricings' => [
[
'price' => 10,
'price_type' => 'adult',
],
[
'price' => 8,
'price_type' => 'senior',
],
[
'price' => 3.5,
'price_type' => 'child',
],
],
]
];
foreach ($showings as $showing) {
2023-02-02 08:17:38 +01:00
$this->command->info("Creating showing for movie {$showing['movie_id']} in room {$room->room_name}");
$s = new \App\Models\Showing();
$s->showing_start = $showing['showing_start'];
$s->movie_id = $showing['movie_id'];
$s->room_id = $showing['room_id'];
$s->user_id = 1;
$s->save();
2023-02-02 08:17:38 +01:00
foreach ($showing['pricings'] as $pricing) {
$p = new \App\Models\Price();
$p->price = $pricing['price'];
$p->price_type = $pricing['price_type'];
$p->showing_id = $s->showing_id;
$p->user_id = 1;
$p->save();
}
}
}
}
}