Skip to content

Commit

Permalink
feat: add coordinates to airport model
Browse files Browse the repository at this point in the history
at the moment, the coordinates are not used for something yet, but they may be needed for a map

fix #194
  • Loading branch information
daveroverts committed Jan 2, 2022
1 parent f261c51 commit 151d5f9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Http/Requests/Airport/Admin/StoreAirport.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function rules()
'icao' => 'required:string|unique:airports|size:4',
'iata' => 'required:string|unique:airports,iata|size:3',
'name' => 'required:string',
'latitude' => ['required', 'regex:/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/'],
'longitude' => ['required', 'regex:/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$/'],
];
}

Expand All @@ -31,6 +33,8 @@ public function attributes()
'icao' => __('ICAO'),
'iata' => __('IATA'),
'name' => __('Name'),
'latitude' => __('Latitude'),
'longitude' => __('Longitude'),
];
}
}
4 changes: 4 additions & 0 deletions app/Http/Requests/Airport/Admin/UpdateAirport.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function rules()
'icao' => 'required:string|between:4,4',
'iata' => 'required:string|between:3,3',
'name' => 'required:string',
'latitude' => ['required', 'regex:/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/'],
'longitude' => ['required', 'regex:/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$/'],
];
}

Expand All @@ -31,6 +33,8 @@ public function attributes()
'icao' => __('ICAO'),
'iata' => __('IATA'),
'name' => __('Name'),
'latitude' => __('Latitude'),
'longitude' => __('Longitude'),
];
}
}
4 changes: 4 additions & 0 deletions app/Imports/AirportsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function model(array $row)
'icao' => $row['icao'],
'iata' => $row['iata'],
'name' => $row['name'],
'latitude' => $row['lat'],
'longitude' => $row['lon'],
]);
}

Expand All @@ -39,6 +41,8 @@ public function rules(): array
'icao' => ['required', 'string', Rule::unique('airports', 'icao')],
'iata' => ['required', 'string', Rule::unique('airports', 'iata')],
'name' => ['required', 'string'],
'lat' => ['required', 'regex:/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/'],
'lon' => ['required', 'regex:/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$/'],
];
}

Expand Down
2 changes: 2 additions & 0 deletions database/factories/AirportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function definition()
'icao' => $this->faker->unique()->regexify('[A-Z]{4}'),
'iata' => $this->faker->unique()->regexify('[A-Z]{3}'),
'name' => $this->faker->name . ' Airport',
'latitude' => $this->faker->latitude(),
'longitude' => $this->faker->longitude(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddCoordinatesInAirports extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('airports', function (Blueprint $table) {
$table->double('longitude')->after('name')->nullable();
$table->double('latitude')->after('name')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('airports', function (Blueprint $table) {
$table->dropColumn(['latitude', 'longitude']);
});
}
}
2 changes: 2 additions & 0 deletions resources/views/airport/admin/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<x-form-input name="icao" :label="__('ICAO')" required maxlength="4" />
<x-form-input name="iata" :label="__('IATA')" required maxlength="3" />
<x-form-input name="name" :label="__('Name')" required />
<x-form-input name="latitude" :label="__('Latitude')" />
<x-form-input name="longitude" :label="__('Longitude')" />

<x-form-submit>
@if ($airport->id)
Expand Down

0 comments on commit 151d5f9

Please sign in to comment.