Laravel works locally but fails in Docker container – “Class not found” error [closed]

Environment

  • Laravel 12+
  • Docker container (latest image)
  • PHP 8.2

The Problem

I have a Laravel application that works perfectly on my local development environment, but when I run the exact same code in a Docker container, I get this error:

Class “AppModelsvehicleStatus” not found

Notice how it’s looking for vehicleStatus (lowercase v) instead of VehicleStatus (uppercase V). The class definitely exists at app/Models/VehicleStatus.php with the correct namespace.

What’s weird

✅ Works fine locally
❌ Fails in Docker container

Same codebase, same image build. The model file exists and has correct namespace: namespace AppModels;

Other models work fine, just this one specific model

Code structure

app/Models/Vehicle.php

public function availabilityRecords(): HasMany
{
    return $this->hasMany(VehicleStatus::class);
}

app/Models/VehicleStatus.php

namespace AppModels;

class VehicleStatus extends Model
{
    // ... model code
}

Vehicle.php

protected $fillable = [
    'registration_number',
    'brand',
    'model',
    'year',
    'vehicle_release_date',
    'mileage',
    'number_of_seats',
    'fuel_type',
    'status',
    'rental_price_per_day',
    'gearbox_type',
    'air_conditioning',
    'vehicle_type',
    'is_sub_rental',
    'partner_id',
    'rental_price_per_day_from_partner',
];

protected $casts = [
    'status' => VehicleStatuses::class,
    'is_sub_rental' => 'boolean',
    'air_conditioning' => 'boolean',
    'rental_price_per_day' => 'decimal:2',
    'rental_price_per_day_from_partner' => 'decimal:2',
    'vehicle_release_date' => 'date:Y-m-d',
    'year' => 'integer',
    'mileage' => 'integer',
    'number_of_seats' => 'integer',
];

// Relationships
public function bookings(): IlluminateDatabaseEloquentRelationsHasMany
{
    return $this->hasMany(Booking::class);
}

public function partner(): IlluminateDatabaseEloquentRelationsBelongsTo
{
    return $this->belongsTo(Partner::class);
}

public function insurances(): IlluminateDatabaseEloquentRelationsHasOne
{
    return $this->hasOne(Insurance::class);
}

public function otherMaintenances(): IlluminateDatabaseEloquentRelationsHasMany
{
    return $this->hasMany(OtherMaintenance::class);
}

public function technicalInspection(): IlluminateDatabaseEloquentRelationsHasOne
{
    return $this->hasOne(TechnicalInspection::class);
}

public function oilChanges(): IlluminateDatabaseEloquentRelationsHasMany
{
    return $this->hasMany(OilChange::class);
}

public function vehicleTaxes(): IlluminateDatabaseEloquentRelationsHasMany
{
    return $this->hasMany(VehicleTax::class);
}

// Fixed relationship - explicitly specify the model class
public function availabilityRecords(): IlluminateDatabaseEloquentRelationsHasMany
{
    return $this->hasMany(VehicleStatus::class, 'vehicle_id');
}

VehicleStatus.php

protected $fillable = [
    'vehicle_id',
    'booking_id',
    'start_date_timestamp',
    'end_date_timestamp',
    'status',
];

protected $casts = [
    'status' => VehicleStatuses::class,
    'start_date_timestamp' => 'datetime:Y-m-d H:i',
    'end_date_timestamp' => 'datetime:Y-m-d H:i',
];

// Relationships
public function vehicle() : BelongsTo
{
    return $this->belongsTo(Vehicle::class);
}

public function booking() : BelongsTo
{
    return $this->belongsTo(Booking::class);
}

What I’ve tried

  • composer dump-autoload
  • php artisan cache:clear
  • php artisan config:clear
  • Restarting container
  • Rebuilding image from scratch
  • Verified file exists and has correct case

The Mystery

Why would Laravel’s autoloader work locally but not in Docker? Has anyone experienced this case-sensitivity issue specifically with Docker containers?

Looking for insights on what could cause this Docker-specific autoloading problem!