Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Airports Laravel Package

ijeffro/laravel-airports

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require ijeffro/laravel-airports dev-master
    

    Add to config/app.php:

    'providers' => [
        ijeffro\Airports\AirportsServiceProvider::class,
    ],
    'aliases' => [
        'Airports' => ijeffro\Airports\AirportsFacade::class,
    ]
    
  2. Publish Config (Optional):

    php artisan vendor:publish --provider="ijeffro\Airports\AirportsServiceProvider"
    

    (Modify config/airports.php if needed, e.g., for custom table names.)

  3. First Use Case: Fetch an airport by IATA code:

    $airport = Airports::getByIata('JFK');
    // Returns: ['iata' => 'JFK', 'name' => 'John F Kennedy Intl', 'city' => 'New York', ...]
    

Implementation Patterns

Core Workflows

  1. Querying Airports:

    • By IATA: Airports::getByIata('LAX')
    • By Name: Airports::getByName('Heathrow')
    • All Airports: Airports::all() (returns Collection of arrays)
    • Filter by Country: Airports::whereCountry('US')
  2. Integration with Eloquent: Add a relationship to a Flight model:

    public function departureAirport()
    {
        return $this->belongsTo(Airport::class, 'departure_iata', 'iata');
    }
    
  3. Validation: Use in Form Requests:

    $this->validate($request, [
        'departure_iata' => 'required|exists:airports,iata',
    ]);
    
  4. Caching: Cache frequent queries (e.g., country dropdowns):

    $countries = Cache::remember('airport_countries', now()->addHours(1), function() {
        return Airports::pluck('country')->unique()->sort();
    });
    

Advanced Patterns

  1. Custom Queries: Extend the facade or service provider to add methods:

    // In a service class
    public function getAirportsByRegion($region)
    {
        return Airports::where('region', $region)->get();
    }
    
  2. API Integration: Use in API responses:

    return AirportResource::collection(Airports::whereCountry($request->country)->get());
    
  3. Seeding: Preload airports in a seeder:

    public function run()
    {
        Airport::insert(Airports::all()->toArray());
    }
    

Gotchas and Tips

Pitfalls

  1. Laravel 5 Compatibility:

    • The dev-master branch is Laravel 5-only. For Laravel 8+, check for updated forks or manual migration.
    • Workaround: Use a database dump from the package and seed your own table.
  2. Case Sensitivity:

    • IATA codes are case-sensitive in queries (e.g., 'jfk''JFK').
    • Fix: Normalize inputs:
      $airport = Airports::getByIata(strtoupper($request->iata));
      
  3. Missing Data:

    • Some airports may lack city, country, or region fields.
    • Tip: Add null checks:
      $city = $airport['city'] ?? 'N/A';
      
  4. Performance:

    • Airports::all() loads ~10,000 records. Cache aggressively or paginate:
      $airports = Airports::paginate(50);
      

Debugging

  1. Table Structure: Run php artisan schema:dump to inspect the airports table schema. Common columns:

    • iata (primary key), name, city, country, region, latitude, longitude.
  2. Missing Facade Methods: Check the AirportsFacade class for available methods. Extend via:

    // In a service provider
    $this->app->bind('Airports', function($app) {
        return new CustomAirportsService($app['Airports']);
    });
    

Extension Points

  1. Custom Fields: Add computed properties to airport data:

    $airportWithDistance = Airports::getByIata('JFK')->merge([
        'distance_km' => $this->calculateDistance($airport, $userLocation),
    ]);
    
  2. Geospatial Queries: Use Laravel Scout or a package like spatie/laravel-geocoding for distance-based searches:

    $nearbyAirports = Airport::near($request->lat . ',' . $request->lng)->get();
    
  3. Localization: Override airport names/cities for multilingual apps:

    $translatedAirport = Airports::getByIata('CDG')->merge([
        'name' => __("airports.{$airport['iata']}.name"),
    ]);
    
  4. Webhooks/Updates: Subscribe to the OpenFlights API for periodic updates and trigger a Laravel job to refresh the database:

    // In a scheduled job
    public function handle()
    {
        Airport::truncate();
        Airport::insert(Airports::all()->toArray());
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime