Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Useful Traits

Laravel Useful Traits Laravel Package

laracraft-tech/laravel-useful-traits

Laravel Useful Additions is a small collection of handy traits and commands for everyday Laravel work, including enum helpers (names, values, array), query scopes like selectAllBut and fromToday/fromYesterday, plus a db:truncate artisan command.

View on GitHub
Deep Wiki
Context7

A collection of useful Laravel additions!

Frequently asked questions about Laravel Useful Traits
How do I install laracraft-tech/laravel-useful-additions in a Laravel app?
Run composer require laracraft-tech/laravel-useful-additions. If you want to customize behavior, publish the config file with php artisan vendor:publish --tag=useful-additions-config. There are no migrations, service contracts, or data backfills involved, so integration is typically a matter of minutes. You then opt in per class by adding the trait to an enum or Eloquent model.
Which Laravel and PHP versions does this package support?
The package tracks Laravel majors explicitly, with support declared up to Laravel 13 in v4.3.0. The UsefulEnums trait requires PHP 8.1 or higher, while UsefulScopes and the db:truncate command are version-agnostic within the supported Laravel range. Because release notes are forward-looking, verify the actual constraints in the package composer.json against your pinned framework and PHP versions before adopting.
Can I use just one trait instead of adopting the whole package?
Yes. The package is really three or four independent micro-features, and each trait attaches at the enum or Eloquent model level, so adoption can be per-class and fully reversible. Nothing in it dictates application structure. One caveat: method names such as names, values, array, selectAllBut, fromToday, and fromYesterday are generic and can collide with existing model traits or magic-method usage, so check your models before enabling them.
What does the UsefulEnums trait do and when is it useful?
It adds names, values, and array helpers to backed enums, returning the case names, the backing values, or an array representation. That is handy when looping over enum cases, building validation rules, or seeding enum values in a migration. It requires PHP 8.1 or higher. It is most valuable in enum-heavy domains such as statuses, roles, and order states where you would otherwise repeat boilerplate.
How does the selectAllBut query scope work?
It introspects the model table columns, caches them, and builds a select statement that excludes the columns you name. The cache is only invalidated when files are added to or removed from the migrations directory, so editing an existing migration does not refresh it. That means a column added in a modified migration, or added out of band, can be silently left out of results after deploy. Add a mandatory cache-clear step to your deployment runbook or keep the scope off hot paths.
What are the risks of using selectAllBut with joins, views, or different databases?
Column introspection runs a cold-cache query per table and does not behave well with joins, views, or dynamic-schema tables. It also produces select-everything queries by default, which conflicts with deliberate column projection and can widen payloads unexpectedly. Introspection and truncation semantics differ between MySQL, PostgreSQL, and SQLite, so test on every engine you support. For most production models, explicit column selection remains the safer default.
How do the fromToday and fromYesterday scopes work?
These UsefulScopes methods constrain a query to records belonging to today or yesterday, saving you from writing repeated whereDate or whereBetween clauses. They are ordinary Eloquent scopes, so they compose with your other query constraints. They do not require any configuration or extra columns beyond the timestamp you scope on. Confirm the exact column they target in your version before relying on them in reports.
Is the db:truncate command safe to run in production?
No. It is destructive by design, and without an environment guard and a force policy it is a production data-loss vector. Treat it strictly as a developer or CI tool rather than an operational one, and decide explicitly whether it is allowed on local dev, CI, or shared staging, and who approves that policy. If you only need it outside production, consider installing the package in require-dev.
Should I use RefreshDatabaseFast instead of Laravel's RefreshDatabase in tests?
No. The maintainer has deprecated RefreshDatabaseFast because rollback is not guaranteed when a test aborts, which can cause cross-test data bleed and flaky suites. Use Laravel's built-in RefreshDatabase trait instead. The performance gain is not worth unreliable test isolation.
Is this package actively maintained, and what are the alternatives?
It is a small, single-maintainer package with a modest star count and essentially no dependents, and activity is mostly dependency bumps plus framework compatibility patches. That is acceptable for something this small and MIT licensed, since you can fork or vendor it if needed, but it is not a dependency to build a strategy on. The main alternatives are writing the handful of helpers yourself or using larger, more established Laravel utility packages. Weigh the convenience of the enum and scope helpers against the maintenance and naming-collision risks per feature.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo