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 Aircrafts Laravel Package

ijeffro/laravel-aircrafts

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require ijeffro/laravel-aircrafts
    

    (Note: Use dev-master for Laravel 5 compatibility if needed.)

  2. Register Service Provider & Facade: Add to config/app.php:

    'providers' => [
        IJeffro\Aircrafts\AircraftsServiceProvider::class,
    ],
    'aliases' => [
        'Aircrafts' => IJeffro\Aircrafts\AircraftsFacade::class,
    ]
    
  3. Publish Config (Optional):

    php artisan vendor:publish --provider="IJeffro\Aircrafts\AircraftsServiceProvider"
    

    (Configures table name for aircraft data.)

  4. First Use Case: Fetch an aircraft by IATA code in a controller:

    use Aircrafts;
    
    $aircraft = Aircrafts::findByIata('A320');
    dd($aircraft->name); // Output: Airbus A320
    

Implementation Patterns

Core Workflows

  1. Data Retrieval:

    • By IATA Code:
      $aircraft = Aircrafts::findByIata('B737');
      
    • By Manufacturer:
      $boeingAircrafts = Aircrafts::where('manufacturer', 'Boeing')->get();
      
    • All Aircrafts:
      $allAircrafts = Aircrafts::all();
      
  2. Integration with Eloquent Models: Add a relationship to a Flight model:

    public function aircraft()
    {
        return $this->belongsTo(Aircraft::class, 'aircraft_iata');
    }
    

    Then fetch:

    $flight->aircraft->name; // e.g., "Boeing 747"
    
  3. Validation: Use the facade to validate IATA codes in Form Requests:

    public function rules()
    {
        return [
            'aircraft_iata' => 'required|exists:aircrafts,iata_code',
        ];
    }
    
  4. Caching: Cache frequent queries (e.g., manufacturer lists):

    $manufacturers = Cache::remember('aircraft_manufacturers', now()->addHours(1), function () {
        return Aircrafts::distinct()->pluck('manufacturer');
    });
    

Advanced Patterns

  • Dynamic Filtering: Combine with Laravel Scout for search:

    use Aircrafts;
    
    $results = Aircrafts::search('787')->get();
    
  • API Responses: Normalize aircraft data for APIs:

    return response()->json([
        'data' => Aircrafts::findByIata($request->aircraft)->toArray(),
    ]);
    
  • Seeding: Publish and seed the aircraft database:

    php artisan vendor:publish --provider="IJeffro\Aircrafts\AircraftsServiceProvider" --tag=migrations
    php artisan migrate
    

Gotchas and Tips

Pitfalls

  1. Laravel 5 Compatibility:

    • The dev-master branch is explicitly for Laravel 5. For Laravel 6+, check for updates or fork the package.
    • Fix: Use composer require ijeffro/laravel-aircrafts:dev-master only if targeting Laravel 5.
  2. Missing Migrations:

    • The package does not auto-migrate the aircraft database. Publish migrations first:
      php artisan vendor:publish --provider="IJeffro\Aircrafts\AircraftsServiceProvider" --tag=migrations
      php artisan migrate
      
  3. Case Sensitivity:

    • IATA codes are case-sensitive in queries. Always use uppercase:
      // Correct:
      Aircrafts::findByIata('A380');
      // Incorrect (may return null):
      Aircrafts::findByIata('a380');
      
  4. Data Freshness:

    • The package ships with a static dataset. For real-time updates, consider:
      • Writing a cron job to sync with an external API (e.g., OpenAirlines).
      • Forking and extending the package to include an updater.

Debugging Tips

  1. Check Published Config: Verify config/aircrafts.php for custom table names or other settings:

    'table' => 'aircrafts', // Default; adjust if needed
    
  2. Query Logs: Enable Laravel query logging to debug slow queries:

    DB::enableQueryLog();
    $aircraft = Aircrafts::findByIata('A320');
    dd(DB::getQueryLog());
    
  3. Facade vs. Direct Model: Prefer the facade for consistency, but use the underlying model (\IJeffro\Aircrafts\Models\Aircraft) for advanced queries:

    use IJeffro\Aircrafts\Models\Aircraft;
    
    $customQuery = Aircraft::where('range_km', '>', 10000)->get();
    

Extension Points

  1. Add Custom Fields: Extend the aircrafts table migration:

    Schema::table('aircrafts', function (Blueprint $table) {
        $table->string('custom_field')->nullable();
    });
    
  2. Create a Decorator: Override the facade to add custom logic:

    class CustomAircraftsFacade extends AircraftsFacade
    {
        public static function getByRange($minRange)
        {
            return parent::where('range_km', '>=', $minRange)->get();
        }
    }
    

    Register it in config/app.php.

  3. Localization: Add translated aircraft names by publishing the language files:

    php artisan vendor:publish --provider="IJeffro\Aircrafts\AircraftsServiceProvider" --tag=lang
    

    Then extend resources/lang/en/aircrafts.php.

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.
nasirkhan/laravel-sharekit
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