3x1io/laravel-overridable-model
A Laravel package for making Eloquent models overridable, so applications and packages can swap in custom model classes through configuration without editing vendor code. Useful for extending third-party packages while keeping your own logic separate and upgrade-safe.
composer require 3x1io/laravel-overridable-model
php artisan vendor:publish --provider="Threex1\OverridableModel\OverridableModelServiceProvider"
config/overridable-model.php (or the package README section on model mapping) first — this is where you register which concrete model class should replace another at resolution time.User/Order model you need to extend without editing vendor/. Point the package's map at your subclass and let your code keep referencing the original class name.Start by overriding one low-risk model (e.g. a package model with a single added scope) and verify it resolves correctly in php artisan tinker before rolling it out across the app.
'overrides' => [
\Vendor\Package\Models\Order::class => \App\Models\Order::class,
],
This keeps the replacement declarative and environment-aware (you can swap implementations per env).boot() for cases where the target depends on tenant, feature flag, or request context:
OverridableModel::override(VendorOrder::class, TenantOrder::class);
booted() behavior — do not change the table unless intentional.HasMany/BelongsTo target where the vendor model is referenced by FQCN.VendorOrder::query() and $user->orders continue to work; only resolution changes. Avoid sprinkling app(Order::class) calls if the package already handles static resolution.get_class(VendorOrder::query()->first()) returns your subclass — this catches registration-order bugs early.php artisan config:clear (and remember config:cache in deploy). Runtime-registered overrides in boot() are unaffected but must run after the package provider.boot() depend on the package provider having booted first. If resolution fails, check bootstrap/providers.php / config/app.php ordering or use $this->app->afterResolving(...).Class not found or silent fallback to the original. Audit hasMany/belongsTo FQCNs after adding an override.Relation::enforceMorphMap() or update morphMap config, otherwise morphTo will return the base class.@method/@property docblocks or a stub on the base model if you rely heavily on static analysis.config('overridable-model.overrides')) and confirm the FQCN string matches exactly (leading backslash and case sensitivity matter). Use php artisan about or a one-off tinker command to inspect the current mapping.How can I help you explore Laravel packages today?