- What is milwad/laravel-attributes and what problem does it solve?
- It is a Laravel package that lets you configure Eloquent models with native PHP 8 attributes instead of repetitive properties and methods. You can declare fillable, hidden, casts, accessors, and similar model settings declaratively, keeping model classes cleaner and easier to scan. It is a model-level utility, not a full framework replacement.
- How do I install milwad/laravel-attributes in a Laravel application?
- Run composer require milwad/laravel-attributes in your Laravel project. Then import the package's attribute classes into the models where you want to use them and apply the attributes as shown in the README. Model-level packages of this kind typically do not require service provider registration or container bindings.
- Which PHP and Laravel versions does milwad/laravel-attributes support?
- Because it uses native PHP attributes, the package requires PHP 8.0 or newer. Check the package's composer.json for the exact Laravel version constraint and test against the Laravel major you run in production. Utility packages that touch model internals should be re-tested after framework upgrades.
- How do I define fillable, hidden, casts, and accessors with PHP attributes?
- You replace boilerplate such as protected $fillable, protected $hidden, protected $casts, and accessor methods with equivalent PHP attributes on the model class. The exact attribute names and syntax are defined in the package README, so follow that reference. Keep one source of truth per concern to avoid duplicate configuration.
- Will milwad/laravel-attributes conflict with existing $fillable, $hidden, or $casts properties?
- Yes, if a model defines both a traditional property and an equivalent attribute, the result depends on how the package resolves precedence. During adoption, remove the old property when you add the attribute and run tests. Do not leave both active in the same model unless the README explicitly documents the behavior.
- Can I use milwad/laravel-attributes on existing Eloquent models?
- Yes, but migrate incrementally. Choose a low-traffic or greenfield model, convert one concern at a time, and verify mass assignment, serialization, casting, and accessor output. Keeping the change small makes it easy to revert or isolate issues.
- Does milwad/laravel-attributes require publishing config files or migrations?
- This package is focused on model configuration, not database schema, so it should not require publishing migrations. Check the README for any optional config file or publishable assets. Your existing migrations remain the source of truth for table structure.
- Is milwad/laravel-attributes production-ready and well maintained?
- Adoption is modest, with a small star count and no dependents, and the package appears to be maintained by a single author. Treat it as a convenience dependency and audit the code paths you rely on. For critical models, weigh the maintenance risk against the boilerplate reduction.
- How does milwad/laravel-attributes compare to native Eloquent or Spatie packages?
- Native Eloquent properties and methods are the baseline and require no dependency. Specialized packages such as Spatie's solve different concerns like slugs, media, or permissions, so they are not direct substitutes. Choose this package only if the attribute syntax meaningfully reduces boilerplate in the models you own.
- How do I test models that use milwad/laravel-attributes, and can I remove it later?
- Your existing Laravel model tests should continue to work; add assertions for fillable, hidden, casts, and accessor output to catch regressions. There is no special test harness required. Because the configuration is declarative, you can remove the package later by replacing attributes with the equivalent properties and methods.