laracraft-tech/laravel-useful-traits
Laravel package with handy daily-use additions: traits for PHP 8.1+ enums (get names/values/array) and Eloquent query scopes (e.g., select all columns except specific ones, date-based scopes), plus an Artisan db:truncate command.
UsefulEnums and UsefulScopes provide utility without enforcing architectural constraints (e.g., no dependency on service containers or custom facades).UsefulEnums for enums, db:truncate for CI/CD).UsefulScopes) could lead to "magic" behavior in models, making them harder to debug or refactor.selectAllBut relies on cached column names, which may introduce hidden complexity in environments with dynamic migrations (e.g., schema-first workflows).RefreshDatabaseFast is obsolete, but its removal may break existing test suites (though the package recommends migrating to Laravel’s built-in trait).RefreshDatabaseFast (though deprecated) or Laravel’s RefreshDatabase.selectAllBut may behave differently across SQL dialects (e.g., column name caching).db:truncate command is ideal for resetting test databases in GitHub Actions, CircleCI, etc., but requires explicit configuration.UsefulScopes in the codebase).selectAllBut cache may stale if migrations are modified without clearing Laravel’s cache (php artisan cache:clear).RefreshDatabaseFast is deprecated, but the package provides clear migration guidance.UsefulEnums) vs. custom implementations?UsefulEnums simplifies these use cases.UsefulScopes?selectAllBut reduce boilerplate in admin panels or data export endpoints?db:truncate or Laravel’s RefreshDatabase may replace custom scripts.selectAllBut cache may require manual clearing post-deployment.selectAllBut introduce unacceptable latency during deployments?uses(RefreshDatabaseFast::class) (though deprecated; migrate to Laravel’s trait).RefreshDatabaseFast or Laravel’s RefreshDatabase.selectAllBut may require adjustments for non-MySQL dialects (e.g., column name caching behavior).db:truncate integrates seamlessly with Laravel Forge, Heroku, or custom scripts for test database resets.jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
- run: composer install
- run: php artisan db:truncate --force # Reset test DB
- run: php artisan test
UsefulEnums).UsefulScopes).db:truncate or Laravel’s trait).UsefulEnums to new/enum-heavy models (e.g., OrderStatus, UserRole).UsefulScopes (e.g., fromToday, selectAllBut).RefreshDatabaseFast to Laravel’s RefreshDatabase in tests.db:truncate scripts with the package’s command.php artisan vendor:publish --tag="useful-additions-config") to customize db:truncate behavior (e.g., excluded tables, foreign key checks)..phpunit.database.checksum to .gitignore if using RefreshDatabaseFast (though deprecated).selectAllBut logic for specific models).db:truncate command supports flags (e.g., --exclude, --force) for granular control.UsefulEnums.UsefulEnums to enum-heavy models (low risk, high reward).UsefulScopes (test thoroughly for edge cases like selectAllBut).RefreshDatabaseFast to Laravel’s trait (critical for CI stability).db:truncate in CI/CD pipelines (replace custom scripts).selectAllBut cache behavior post-migration.fromToday/fromYesterday scopes with timezone-aware applications.db:truncate handles foreign keys and transactions correctly.selectAllBut cache requires manual clearing during schema changes (add to deployment checklist).RefreshDatabaseFast is unsupported; migrate tests proactively.UsefulEnums vs. native enums).UsefulScopes with edge cases (e.g., empty tables, null columns).How can I help you explore Laravel packages today?