- How do I install thefeqy/laravel-model-status in a Laravel application?
- Install it with Composer using composer require thefeqy/laravel-model-status, then add the HasActiveScope trait to the Eloquent models that need status handling. You will also need a status column on the corresponding tables, which the package's Artisan command and documentation help you scaffold. Run your migrations and confirm the package's service provider is discovered before using the trait or middleware.
- Which Laravel and PHP versions does thefeqy/laravel-model-status support?
- The supported Laravel and PHP matrix is defined by the package's composer.json constraints, so check those before upgrading. The v1.5.0 release is described as a minor upgrade with a normal composer update path and no migration called out. Confirm compatibility against your application's Laravel and PHP versions and run your test suite after updating.
- Why does $model->status return a Status object instead of a string in v1.5.0?
- Version 1.5.0 introduces a StatusCast that casts the status attribute to a Status object rather than a plain scalar. That is a behavioral change for code that compares status to strings, validates it as a scalar, serializes it directly, or passes it through API responses. If you need the underlying database value, use getRawOriginal('status'), and update comparisons, Blade templates, filters, and test assertions to work with the Status enum.
- How do I query only active records with the HasActiveScope trait?
- Add the HasActiveScope trait to your model and use the provided active scope to constrain queries to models whose status is active. This keeps active-record filtering consistent across your application instead of repeating where clauses. Because status is cast to a Status object, verify that any custom query scopes and filters you combine with it still behave as expected.
- How does cascade deactivation work in laravel-model-status v1.5.0?
- Cascade deactivation is opt-in and must be explicitly configured on the models or relationships where it applies, so it does not activate automatically. When enabled, deactivating a parent can also deactivate its related models, which introduces multi-model writes you should test carefully. Review recursion, cycle protection, transaction boundaries, model events, authorization policies, soft deletes, and global scopes before enabling it on production relationships.
- Can I use the package's middleware to block inactive users from accessing routes?
- Yes, the package ships middleware for ensuring only active users proceed through your routes. Register the middleware and attach it to the route groups or guards where inactive accounts should be rejected. Test the response for inactive users, including API requests, so the middleware behaves consistently with your authentication and authorization flow.
- What Artisan command does thefeqy/laravel-model-status provide?
- The package includes a custom Artisan command that streamlines adding status columns to models and migrations. Run php artisan list to see the exact command signature and available options in your installed version. Review the generated migration and model changes before committing them, especially if you already have a status column.
- Is this package a good fit for complex workflows or state machines?
- The package is designed for simple lifecycle management such as active and inactive status, not for complex workflow or state-machine requirements. If you need many states, guarded transitions, and audit trails, a dedicated state-machine package is usually a better fit. This package is strongest on back-office and administrative models with clear parent-child ownership.
- Is upgrading from v1.4.0 to v1.5.0 a breaking change?
- It is released as a minor version upgrade with no migration called out, but the StatusCast is a runtime behavior change. Audit every place you compare status to a string, validate it, serialize it, or expose it through an API before rolling out. Upgrade in a branch, run composer update, and execute your full test suite, static analysis, and API contract tests first.
- How should I test status changes and cascade deactivation before deploying?
- Add tests that assert the status attribute is the expected Status enum case and use assertDatabaseHas to verify the stored value. For cascade deactivation, pilot it on one simple parent-child relationship and test transactions, model events, authorization policies, soft deletes, and partial failures. Introduce cascade behavior on low-risk administrative models before applying it to high-volume or financially sensitive relationships.