2017-12-13 11:50:55 +08:00
|
|
|
<?php
|
|
|
|
|
2019-11-06 00:44:31 +08:00
|
|
|
use App\Models\Enums\PirepSource;
|
|
|
|
use App\Models\Enums\PirepState;
|
|
|
|
use App\Models\Enums\PirepStatus;
|
2018-01-03 04:31:00 +08:00
|
|
|
use Carbon\Carbon;
|
2017-12-13 11:50:55 +08:00
|
|
|
use Faker\Generator as Faker;
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
/*
|
2017-12-13 11:50:55 +08:00
|
|
|
* Create a new PIREP
|
|
|
|
*/
|
2017-12-26 05:19:34 +08:00
|
|
|
$factory->define(App\Models\Pirep::class, function (Faker $faker) {
|
2020-05-23 23:43:29 +08:00
|
|
|
$airline = factory(\App\Models\Airline::class)->create();
|
|
|
|
$flight = factory(\App\Models\Flight::class)->create([
|
2019-11-06 00:44:31 +08:00
|
|
|
'airline_id' => $airline->id,
|
|
|
|
]);
|
|
|
|
|
2017-12-13 11:50:55 +08:00
|
|
|
return [
|
2018-08-27 00:40:04 +08:00
|
|
|
'id' => $faker->unique()->numberBetween(10, 10000000),
|
2019-11-06 00:44:31 +08:00
|
|
|
'airline_id' => function () use ($airline) {
|
|
|
|
return $airline->id;
|
2017-12-26 05:19:34 +08:00
|
|
|
},
|
2018-08-27 00:40:04 +08:00
|
|
|
'user_id' => function () {
|
2020-05-23 23:43:29 +08:00
|
|
|
return factory(\App\Models\User::class)->create()->id;
|
2017-12-13 11:50:55 +08:00
|
|
|
},
|
2018-08-27 00:40:04 +08:00
|
|
|
'aircraft_id' => function () {
|
2020-05-23 23:43:29 +08:00
|
|
|
return factory(\App\Models\Aircraft::class)->create()->id;
|
2017-12-13 11:50:55 +08:00
|
|
|
},
|
2019-11-06 00:44:31 +08:00
|
|
|
'flight_id' => function () use ($flight) {
|
|
|
|
return $flight->id;
|
|
|
|
},
|
|
|
|
'flight_number' => function () use ($flight) {
|
|
|
|
return $flight->flight_number;
|
2017-12-13 11:50:55 +08:00
|
|
|
},
|
2018-08-27 00:40:04 +08:00
|
|
|
'route_code' => null,
|
|
|
|
'route_leg' => null,
|
2019-11-06 00:44:31 +08:00
|
|
|
'dpt_airport_id' => function () use ($flight) {
|
|
|
|
return $flight->dpt_airport_id;
|
2017-12-13 11:50:55 +08:00
|
|
|
},
|
2019-11-06 00:44:31 +08:00
|
|
|
'arr_airport_id' => function () use ($flight) {
|
|
|
|
return $flight->arr_airport_id;
|
2017-12-14 00:56:26 +08:00
|
|
|
},
|
2018-03-20 09:50:40 +08:00
|
|
|
'level' => $faker->numberBetween(20, 400),
|
|
|
|
'distance' => $faker->randomFloat(2, 0, 6000),
|
|
|
|
'planned_distance' => $faker->randomFloat(2, 0, 6000),
|
|
|
|
'flight_time' => $faker->numberBetween(60, 360),
|
2018-02-12 10:38:56 +08:00
|
|
|
'planned_flight_time' => $faker->numberBetween(60, 360),
|
2018-03-20 09:50:40 +08:00
|
|
|
'zfw' => $faker->randomFloat(2),
|
2019-07-23 20:41:20 +08:00
|
|
|
'block_fuel' => $faker->randomFloat(2, 0, 1000),
|
|
|
|
'fuel_used' => function (array $pirep) {
|
|
|
|
return round($pirep['block_fuel'] * .9, 2); // 90% of the fuel loaded was used
|
|
|
|
},
|
2019-07-23 20:43:40 +08:00
|
|
|
'block_on_time' => Carbon::now('UTC'),
|
|
|
|
'block_off_time' => function (array $pirep) {
|
2018-04-05 02:03:10 +08:00
|
|
|
return $pirep['block_on_time']->subMinutes($pirep['flight_time']);
|
|
|
|
},
|
2018-08-27 00:40:04 +08:00
|
|
|
'route' => $faker->text(200),
|
|
|
|
'notes' => $faker->text(200),
|
|
|
|
'source' => $faker->randomElement([PirepSource::MANUAL, PirepSource::ACARS]),
|
2019-11-06 00:44:31 +08:00
|
|
|
'source_name' => 'TestFactory',
|
2018-08-27 00:40:04 +08:00
|
|
|
'state' => PirepState::PENDING,
|
|
|
|
'status' => PirepStatus::SCHEDULED,
|
|
|
|
'submitted_at' => Carbon::now('UTC')->toDateTimeString(),
|
|
|
|
'created_at' => Carbon::now('UTC')->toDateTimeString(),
|
|
|
|
'updated_at' => function (array $pirep) {
|
2017-12-13 11:50:55 +08:00
|
|
|
return $pirep['created_at'];
|
|
|
|
},
|
|
|
|
];
|
|
|
|
});
|