flairuk / laravel-airlines
IATA airline codes for Laravel: an in-memory lookup API, validation rule and optional database table.
Requires
- php: ^8.2
- illuminate/console: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- illuminate/validation: ^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0|^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-05 11:04:01 UTC
README
Laravel Airlines — IATA airline designators (BA, EK, QF, …) for Laravel 12 and 13.
- No database required. Look airlines up through a facade backed by an in-memory dataset.
- Typed results. Every lookup returns readonly
Airlineobjects in Laravel collections. - Validation rule.
new AirlineCodeaccepts known designators only. - Optional table. Publish a migration and seed an
airlinestable when other tables need to reference airlines.
📦 Installation · 🚀 Usage · 💾 Database table · 🔄 Upgrading
📦 Installation
composer require flairuk/laravel-airlines
Requires PHP 8.2 or later with Laravel 12, or PHP 8.3 or later with Laravel 13.
Laravel discovers the service provider and the Airlines facade automatically.
🚀 Usage
use FLAIRUK\Airlines\Facades\Airlines; Airlines::find('BA'); // Airline { id: 301, code: "BA", name: "British Airways", countryCode: "GB", countryName: "United Kingdom" } Airlines::findOrFail('BA'); // throws ItemNotFoundException for unknown codes Airlines::exists('ba'); // true (codes are case-insensitive) Airlines::findById(301); Airlines::all(); // Collection<Airline> Airlines::inCountry('GB'); // airlines registered in the UK Airlines::search('british'); // matches on name or exact code Airlines::codes(); // ['00', '01', ..., 'ZZ']
IATA re-issues designators, so a code can belong to more than one airline. find() returns the first one and allWithCode('1I') returns every match.
Select options
Airlines::options(); // [301 => 'British Airways', ...] keyed by id, sorted by name Airlines::options('code'); // ['BA' => 'British Airways', ...]
Validation
use FLAIRUK\Airlines\Rules\AirlineCode; $request->validate([ 'airline' => ['required', new AirlineCode], ]);
Dependency injection
The facade resolves a singleton FLAIRUK\Airlines\Airlines, which you can type-hint instead:
public function __construct(private \FLAIRUK\Airlines\Airlines $airlines) {}
💾 Database table (optional)
If you need airlines in your database, for example for foreign keys or joins:
php artisan airlines:install # publish config + migration, then ask to migrate and seed php artisan airlines:install --migrate # migrate and seed without asking
This command publishes config/airlines.php and a migration, then offers to run migrate and seed the table. You can re-seed at any time; it upserts rows, so re-running is safe:
php artisan airlines:seed # insert / update php artisan airlines:seed --prune # also delete rows no longer in the dataset
You can also call the seeder from your own DatabaseSeeder:
$this->call(\FLAIRUK\Airlines\Database\AirlinesSeeder::class);
Query the table through the bundled Eloquent model:
use FLAIRUK\Airlines\Models\Airline; Airline::code('BA')->first(); Airline::inCountry('GB')->orderBy('name')->get();
The table name and connection come from AIRLINES_TABLE and AIRLINES_DB_CONNECTION, or from the published config.
🔄 Upgrading from dev-master
Version 1.0 is a rewrite. Breaking changes:
| dev-master | 1.0 |
|---|---|
Package ijeffro/laravel-airlines |
flairuk/laravel-airlines |
ijeffro\Airlines\… namespace |
FLAIRUK\Airlines\… |
Facade ijeffro\Airlines\AirlinesFacade |
FLAIRUK\Airlines\Facades\Airlines (auto-discovered) |
Airlines::getList($sort) (array) |
Airlines::all()->sortBy($property, SORT_NATURAL | SORT_FLAG_CASE) (Collection of Airline; properties are camelCase, e.g. countryCode) |
Airlines::getOne($id) |
Airlines::findById($id) |
Airlines::getListForSelect() |
Airlines::options() |
php artisan airlines:migration (generated seeder in database/seeds) |
php artisan airlines:install / airlines:seed |
Config key airlines.table_name |
airlines.table |
charify MySQL migration |
removed. code and country_code are CHAR from the start |
Row ids are unchanged, so existing foreign keys stay valid. The dataset was also cleaned:
- 12 rows whose code was not a valid two-character designator (e.g.
&T,??) were removed. - 4 exact duplicate rows were removed.
- Missing country codes were filled in where the country was known.
- Empty strings are now
null.
After upgrading, run php artisan airlines:seed --prune to update a seeded table.
Warning
The dev-master migration made country_code and country_name NOT NULL, but ten airlines in 1.0 have no country, so seeding an old table fails. Make the two columns nullable first, in a migration of your own:
Schema::table('airlines', function (Blueprint $table) { $table->string('country_code', 2)->nullable()->change(); $table->string('country_name')->nullable()->change(); });
Or drop the old table and create it again with php artisan airlines:install.
🧪 Testing
composer test
📄 License
MIT. See LICENSE.