artisanbr/generic-model
artisanbr/generic-model offers a reusable generic base model for Laravel Eloquent, helping standardize common model behavior, reduce boilerplate, and keep CRUD-ready models consistent across your application. Useful for quick scaffolding and cleaner code.
v2.0.1 is a housekeeping release — the changelog is a single merge commit ("Version/1.0.0 merge") plus a first-time contributor credit, with no documented API changes, deprecations, or breaking changes between v2.0.0 and v2.0.1. Treat it as a safe patch bump, but because the notes carry no upgrade guidance, verify the diff before bumping a production app.
Minimal path to first use:
composer require artisanbr/generic-model and check composer.json in the package for the actual PHP/Laravel constraints — v2.x is the current major line, so assume a modern Laravel skeleton (PHP 8+) and confirm before installing into an older app.src/ directory: the base class (typically GenericModel) and any trait it composes are the whole API surface. The README is thin relative to the code, so read the base class rather than trusting the docs.php artisan vendor:publish --provider="ArtisanBr\GenericModel\GenericModelServiceProvider". If no provider is registered, skip this — the package may be pure class inheritance with no container bindings.extends Model with extends GenericModel on one non-critical model and confirm nothing breaks.use ArtisanBr\GenericModel\GenericModel;
class Post extends GenericModel
{
protected $fillable = ['title', 'body', 'status'];
}
Run your existing test suite against that single model before converting others.
Adopt one model at a time. Convert a leaf model (no children depending on its behaviour) first, exercise its full CRUD path, then migrate the rest. The failure modes of a generic base class show up in mass assignment and query building, so a canary model catches most of them.
Keep domain logic in the subclass. The value of a generic model is standardised create/read/update/delete and search/pagination behaviour. Resist putting business rules in the base layer; override per-model instead so a future major version doesn't ripple through your domain.
Wrap it behind a repository or service if you use the query helpers widely. A generic base class is convenient but couples every model to the package's method signatures. If the package's fluent search/listing helpers are used in controllers, funnel them through a repository so the v3 upgrade is a single-file change.
Use it as a consistent API resource layer. The strongest day-to-day pattern is: thin controller → repository/service → generic model. The model handles persistence and standard filtering; the service handles authorisation and domain invariants.
Fillable/guarded discipline. When a base class provides a generic create/update path, verify how it treats $request->all(). Prefer explicit DTOs or validated arrays over raw request payloads passed into any generic create method.
Testing. Add a small contract test per converted model asserting create/update/delete and one filtered listing. That gives you a regression net for future patch releases, which this package's changelog won't provide.
v2.0.1 documents a branch merge only. Before upgrading, run composer update artisanbr/generic-model --with-dependencies on a branch and diff vendor/artisanbr/generic-model/src. Watch for signature changes on overridden methods in your subclasses.find, all, create, update, delete wrappers. If your subclass overrides Eloquent's versions, confirm the base isn't calling parent:: in a way that skips your override — or vice versa.fill() or forceFill(). Confirm whether $guarded is respected; forceFill bypasses it entirely.$with but rarely infer relations from filters. Add $with on the model or pass it through the query layer.Model::preventLazyLoading() in local/testing to surface them early.Version/1.0.0 merged into a v2.x line. If you're on v1.x and reading v2 docs (or vice versa), the API differs. Pin the major version in composer.json ("artisanbr/generic-model": "^2.0") so a surprise major doesn't land via a loose constraint.App\Models\BaseModel extends GenericModel) as your own stable seam — every app model extends that, so a package swap or upgrade touches one file.How can I help you explore Laravel packages today?