2017-12-13 11:50:55 +08:00
|
|
|
<?php
|
|
|
|
|
2017-12-20 10:19:36 +08:00
|
|
|
use App\Models\Enums\PirepSource;
|
|
|
|
use App\Models\Enums\PirepState;
|
2017-12-13 11:50:55 +08:00
|
|
|
use Faker\Generator as Faker;
|
|
|
|
|
|
|
|
# Match the list available in tests/data/*.yml
|
|
|
|
|
|
|
|
$airlinesAvailable = [1];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new PIREP
|
|
|
|
*/
|
|
|
|
$factory->define(App\Models\Pirep::class, function (Faker $faker) use ($airlinesAvailable) {
|
|
|
|
|
|
|
|
static $raw_data;
|
|
|
|
|
|
|
|
return [
|
2017-12-13 12:13:11 +08:00
|
|
|
'id' => substr($faker->unique()->sha1, 0, 12),
|
2017-12-14 00:56:26 +08:00
|
|
|
'airline_id' => 1, #$faker->randomElement($airlinesAvailable),
|
2017-12-13 11:50:55 +08:00
|
|
|
'user_id' => function () { # OVERRIDE THIS IF NEEDED
|
|
|
|
return factory(App\Models\User::class)->create()->id;
|
|
|
|
},
|
|
|
|
'aircraft_id' => function () {
|
|
|
|
return factory(App\Models\Aircraft::class)->create()->id;
|
|
|
|
},
|
|
|
|
'flight_number' => function () {
|
|
|
|
return factory(App\Models\Flight::class)->create()->flight_number;
|
|
|
|
},
|
|
|
|
'route_code' => function(array $pirep) {
|
2017-12-14 00:56:26 +08:00
|
|
|
//return App\Models\Flight::where(['flight_number' => $pirep['flight_number']])->first()->route_code;
|
2017-12-13 11:50:55 +08:00
|
|
|
},
|
|
|
|
'route_leg' => function (array $pirep) {
|
2017-12-14 00:56:26 +08:00
|
|
|
//return App\Models\Flight::where('flight_number', $pirep['flight_number'])->first()->route_leg;
|
2017-12-13 11:50:55 +08:00
|
|
|
},
|
|
|
|
'dpt_airport_id' => function () {
|
|
|
|
return factory(App\Models\Airport::class)->create()->id;
|
|
|
|
},
|
2017-12-14 00:56:26 +08:00
|
|
|
'arr_airport_id' => function () {
|
|
|
|
return factory(App\Models\Airport::class)->create()->id;
|
|
|
|
},
|
2017-12-13 11:50:55 +08:00
|
|
|
'flight_time' => $faker->randomFloat(2),
|
2017-12-14 01:38:03 +08:00
|
|
|
'route' => $faker->text(200),
|
|
|
|
'notes' => $faker->text(200),
|
2017-12-20 10:19:36 +08:00
|
|
|
'source' => $faker->randomElement([PirepSource::MANUAL, PirepSource::ACARS]),
|
|
|
|
'state' => PirepState::PENDING, //$faker->randomElement([-1, 0, 1]), # REJECTED/PENDING/ACCEPTED
|
2017-12-13 11:50:55 +08:00
|
|
|
'raw_data' => $raw_data ?: $raw_data = json_encode(['key' => 'value']),
|
|
|
|
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
|
|
|
|
'updated_at' => function(array $pirep) {
|
|
|
|
return $pirep['created_at'];
|
|
|
|
},
|
|
|
|
];
|
|
|
|
});
|