- Can I use this package to replace Eloquent for database models in Laravel?
- No, this package is not a full ORM replacement. It lacks query building, relationships, and migrations—use it only for non-database models like DTOs, API payloads, or caching layers. For database models, stick with Eloquent.
- How do I install `jenssegers/model` in a Laravel project?
- Run `composer require jenssegers/model` in your project root. No additional Laravel-specific configuration is required, though avoid naming conflicts with existing Eloquent models.
- Does this package support attribute casting like Eloquent?
- Yes, it supports casting (e.g., `protected $casts = ['age' => 'integer']`) just like Eloquent. Casts work identically for serialization to arrays or JSON.
- Will this work with Laravel 10+? Are there version compatibility issues?
- The package is framework-agnostic and should work with Laravel 10+. However, test thoroughly for edge cases, as it lacks Laravel’s service container integration. No Eloquent-specific features (like query builder) are supported.
- How do I handle data persistence (saving/loading) with this model?
- This package doesn’t include persistence logic. Override the `save()` method manually (e.g., for API calls, file storage, or Redis) and implement `load()` if needed. Example: `return API::post('/items', $this->attributes);`.
- Can I use hidden/guarded/appended attributes like Eloquent?
- Yes, it fully supports `$hidden`, `$guarded`, and `$appends` just like Eloquent. These work during `toArray()` or `toJson()` serialization, hiding sensitive fields or appending computed attributes.
- Is this package actively maintained? When was the last update?
- Check the GitHub repo for recent activity, but the package appears lightweight and stable. As of 2026 (placeholder), verify the `composer.json` for the latest release date. No Laravel-specific dependencies mean lower maintenance risk.
- How do I test accessors/mutators in PHPUnit?
- Test accessors/mutators by instantiating the model, setting attributes, and asserting the transformed values. Example: `$user = new User(['birthday' => '1990-01-01']); $this->assertInstanceOf(DateTime::class, $user->birthday);`. Use unit tests for logic and integration tests for serialization.
- What’s the performance impact compared to native PHP arrays/objects?
- This package adds minimal overhead for serialization (e.g., casting, hidden fields). Benchmark against native arrays/objects for critical paths, but expect ~10–20% slower serialization due to reflection and accessor calls.
- Are there alternatives for lightweight Laravel models without ORM?
- For Laravel, consider `spatie/array-to-object` for simple DTOs or `laravel/serializable-closure` for custom serialization. For Eloquent-like features without persistence, this package is a solid choice, but evaluate `illuminate/support` traits if you need Laravel-specific helpers.