File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed
app/Services/ImportExport
resources/views/admin/subfleets Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use App \Contracts \ImportExport ;
6
6
use App \Models \Aircraft ;
7
+ use App \Models \Airline ;
7
8
use App \Models \Enums \AircraftState ;
8
9
use App \Models \Enums \AircraftStatus ;
9
10
use App \Models \Subfleet ;
@@ -32,19 +33,21 @@ class AircraftImporter extends ImportExport
32
33
];
33
34
34
35
/**
35
- * Find the subfleet specified, or just create it on the fly
36
+ * Find the subfleet specified, or just create it on the fly and attach it to the
37
+ * first airline that's been found
36
38
*
37
39
* @param $type
38
40
*
39
41
* @return Subfleet|\Illuminate\Database\Eloquent\Model|null|object|static
40
42
*/
41
43
protected function getSubfleet ($ type )
42
44
{
43
- $ subfleet = Subfleet::firstOrCreate ([
45
+ return Subfleet::firstOrCreate ([
44
46
'type ' => $ type ,
45
- ], ['name ' => $ type ]);
46
-
47
- return $ subfleet ;
47
+ ], [
48
+ 'name ' => $ type ,
49
+ 'airline_id ' => Airline::where ('active ' , true )->first ()->id ,
50
+ ]);
48
51
}
49
52
50
53
/**
Original file line number Diff line number Diff line change 15
15
{{ $subfleet -> name } }
16
16
</a >
17
17
</td >
18
- <td >{{ $subfleet -> airline -> name } } </td >
18
+ <td >{{ optional ( $subfleet -> airline ) -> name } } </td >
19
19
<td >{{ $subfleet -> type } } </td >
20
20
<td >{{ $subfleet -> aircraft -> count () } } </td >
21
21
<td class =" text-right" >
Original file line number Diff line number Diff line change @@ -564,7 +564,8 @@ public function testFlightImporterEmptyCustomFields(): void
564
564
*/
565
565
public function testAircraftImporter (): void
566
566
{
567
- $ subfleet = factory (App \Models \Subfleet::class)->create (['type ' => 'A32X ' ]);
567
+ factory (App \Models \Airline::class)->create ();
568
+ // $subfleet = factory(App\Models\Subfleet::class)->create(['type' => 'A32X']);
568
569
569
570
$ file_path = base_path ('tests/data/aircraft.csv ' );
570
571
$ status = $ this ->importSvc ->importAircraft ($ file_path );
@@ -579,8 +580,9 @@ public function testAircraftImporter(): void
579
580
580
581
$ this ->assertNotNull ($ aircraft );
581
582
$ this ->assertNotNull ($ aircraft ->hex_code );
582
- $ this ->assertEquals ($ subfleet ->id , $ aircraft ->id );
583
- $ this ->assertEquals ($ subfleet ->type , $ aircraft ->subfleet ->type );
583
+ $ this ->assertNotNull ($ aircraft ->subfleet );
584
+ $ this ->assertNotNull ($ aircraft ->subfleet ->airline );
585
+ $ this ->assertEquals ('A32X ' , $ aircraft ->subfleet ->type );
584
586
$ this ->assertEquals ('A320-211 ' , $ aircraft ->name );
585
587
$ this ->assertEquals ('N309US ' , $ aircraft ->registration );
586
588
$ this ->assertEquals (null , $ aircraft ->zfw );
You can’t perform that action at this time.
0 commit comments