- What is qsomazzi/particle and what problem does it solve in Laravel?
- Particle is a lightweight Laravel package for attaching small, reusable pieces of data called particles to Eloquent models as dynamic attributes. It lets you extend models without changing your database schema and keeps related configuration and business logic close to where it belongs. It installs via Composer and is designed for zero-config setup with sensible defaults.
- How do I install qsomazzi/particle with Composer?
- Install the package with Composer using composer require qsomazzi/particle. It is built for Laravel and follows framework conventions, so it is intended to drop into existing projects with minimal configuration. Check the repository README and composer.json for any version-specific setup notes before installing.
- Do I need to run migrations or change my database schema to use Particle?
- No. Particle is schema-free: it attaches dynamic attributes to Eloquent models without touching your database schema. That helps you avoid scattering one-off columns, accessors, and form-request logic through migrations. Your normal application migrations still apply to the rest of your data model.
- How do I define a particle and attach it to an Eloquent model?
- Particle provides a fluent, chainable API that you use inside your Eloquent models to declare particles. You define a particle once and then attach it where needed, keeping configuration and business logic close to the model instead of spreading it across migrations and accessors. Refer to the repository README for the exact method names and syntax for your installed version.
- Can I reuse the same particle definition across multiple Eloquent models?
- Yes. Particle is designed around defining a particle once and reusing it across models in your application. This keeps shared configuration and business logic in one place instead of duplicating accessors or validation rules. The fluent API is intended to read naturally inside each model that uses it.
- Does Particle work with Laravel casts, validation, and serialization?
- Particle is described as playing nicely with Laravel casts, validation, and serialization, so dynamic attributes can participate in the same workflows as regular model attributes. That means you can validate incoming data and cast values without adding database columns. Confirm any edge cases against the README and test suite for your version.
- Which Laravel versions does qsomazzi/particle support?
- Particle is built for Laravel and follows framework conventions, but the exact supported Laravel and PHP versions are declared in its composer.json on the repository. Check that file before installing to confirm compatibility with your application's framework version. Because the package relies on Eloquent behavior, it fits naturally into standard Laravel projects.
- How does Particle handle serialization of dynamic attributes in toArray and toJson?
- Particle is designed to play nicely with Laravel serialization, so dynamic attributes can appear when models are converted with toArray or toJson. Verify the exact output shape in your application, especially if the model has hidden or appended attributes configured. Reusable definitions help keep serialization behavior consistent across models.
- Is Particle suitable for production, and are there performance concerns?
- Particle is described as lightweight and zero-config, making it suitable for typical Laravel applications that need small reusable dynamic attributes. The main consideration is how often those attributes are resolved, particularly when serializing large collections or performing expensive logic inside particle definitions. Keep definitions focused and benchmark against your own read patterns before relying on them heavily.
- How do I test models that use Particle, and what alternatives should I compare?
- You can test models that use Particle the same way you test other Eloquent models, using your existing Laravel testing setup and database or in-memory SQLite. Because particles are schema-free dynamic attributes, there are no extra package tables to migrate in your test database. Alternatives worth comparing include JSON columns, custom accessors and mutators, and dedicated attribute packages; weigh them against Particle's reusable definitions and fluent API.