Laravel Tips
Curated Laravel, PHP, and Pest tips by Punyapal Shah and the community.
- Assert JSON Columns and Backed Enums with assertDatabaseHaslaravel/utilities/laravel-assert-database-has-json-enums.md
- Auto-Scale Queue Workers with --stop-when-empty-for in Laravellaravel/queue/laravel-queue-worker-stop-when-empty-for.md
- Automate Laravel 11 casts() Method Upgrade with Rectorlaravel/eloquent/laravel-rector-automate-casts-method-upgrade.md
- Automate PHP Readonly Class Refactoring with Rectorphp/tooling/php-rector-automate-readonly-classes.md
- Automatically Discard Orphaned Queue Jobs with deleteWhenMissingModelslaravel/queue/laravel-queue-delete-when-missing-models.md
- Build Conditional Transformation Pipelines with Collection::when() and whenEmpty()laravel/collections/laravel-collection-when-conditional-pipelines.md
- Cache Playwright and Puppeteer Browsers in GitHub Actionsgit/github-actions/github-actions-cache-playwright-puppeteer.md
- Cast Enums Inside JSON and Array Column Keys in Eloquentlaravel/eloquent/laravel-cast-enum-json-array-key.md
- Catch Unmocked External API Calls with Http::preventStrayRequests()laravel/testing/laravel-http-fake-prevent-stray-requests.md
- Centralized Application Activity Logging with Laravel Event Subscriberslaravel/events/laravel-activity-log-event-subscriber.md
- Choose the Right Processing Method: chunk(), lazy(), chunkById(), lazyById()laravel/eloquent/laravel-chunk-vs-lazy-by-id.md
- Clean Up Complex Multi-Step Operations with Illuminate Pipelinelaravel/eloquent/laravel-pipeline-pattern-complex-workflows.md
- Clean Up Redundant Code Comments with a Custom Rector Rulephp/tooling/php-rector-remove-unnecessary-comments.md
- Combine Custom Casts and Enums for Complex Attributeslaravel/eloquent/laravel-custom-casts-enum-json.md
- Complete Guide to PHPStan Static Analysis Levels (0 to 10)php/tooling/phpstan-static-analysis-levels-guide.md
- Define Custom Macros on the Eloquent Builderlaravel/eloquent/laravel-builder-macro-registration.md
- Detect AI Agents in Laravel with AgentDetector and PAOlaravel/configuration/laravel-agent-detector-pao.md
- Detect Cumulative Database Query Spikes with whenQueryingForLongerThan()laravel/database/laravel-db-when-querying-for-longer-than.md
- Detect and Eliminate N+1 Queries in Development with preventLazyLoading()laravel/eloquent/laravel-eloquent-prevent-lazy-loading-strict-mode.md
- Dispatch Jobs After Transaction Commit with DB::afterCommit()laravel/queue/laravel-db-after-commit-transaction-jobs.md
- Ditch sleep() in Tests: Use Laravel Time Travel Helperslaravel/configuration/laravel-test-time-travel-freeze.md
- Efficient Unique Slug Generation in Eloquent Without Looping Querieslaravel/eloquent/laravel-generate-unique-slug-without-looping.md
- Execute Multi-Step Business Workflows with the Pipeline Facadelaravel/architecture/laravel-pipeline-send-multi-step-workflows.md
- Fix Blade View Cache Compilation for Teleport Directives in Livewirelivewire/components/livewire-teleport-blade-view-cache-directive-fix.md
- Freeze and Inspect Application Time in Tests with Carbon setTestNow()laravel/testing/laravel-carbon-set-test-now-time-manipulation.md
- Generic Classes and Functions in PHP Using PHPDoc @templatephp/tooling/php-generics-phpdoc-template.md
- Git Submodule vs. Git Subtree: Which Should You Use?git/workflow/git-submodule-vs-git-subtree.md
- Ignore Local Files Without Modifying .gitignore Using .git/info/excludegit/workflow/git-local-ignore-info-exclude.md
- Index Dynamic JSON Attributes with Generated Virtual Columnslaravel/database/laravel-database-generated-virtual-columns.md
- Integer Enums: Start Indexing from 1, Avoid 0php/basics/php-backed-integer-enums-indexing.md
- Log and Audit Slow Database Queries with DB::listen()laravel/database/laravel-db-listen-slow-query-logging.md
- Mask Query Bindings in Laravel Exception Messageslaravel/database/mask-query-bindings-in-exception-messages.md
- Multi-Tenant Team Scoping with a Reusable BelongsToTeam Model Traitlaravel/architecture/laravel-belongs-to-team-multitenancy-trait.md
- Never Return Statements inside Finally Blocks in PHPphp/basics/php-never-return-in-finally-block.md
- Optimize Date Queries by Replacing whereYear() with whereBetween()laravel/eloquent/laravel-eloquent-where-year-vs-date-between-index.md
- Optimize Queue Worker Polling Overheads in Productionlaravel/queue/laravel-queue-worker-polling-optimization.md
- Prevent Duplicate Redis and Database Lookups with Cache::memo()laravel/http-api/laravel-cache-memo-driver-in-memory.md
- Prevent Information Disclosure with Gate::denyAsNotFound()laravel/eloquent/laravel-gate-deny-as-not-found-security.md
- Prevent Navigation Layout Shifts and Flickering in Web Applicationscss/styling/css-prevent-navigation-layout-shift-flicker.md
- Prevent Queue Payload Bloat with withoutRelations()laravel/queue/laravel-queue-without-relations-serialization.md
- Protect Custom Artisan Commands from AI Agents with Prohibitablelaravel/eloquent/laravel-prohibitable-custom-commands-agents.md
- Protect Production with Laravel Prohibitable Commandslaravel/configuration/laravel-prohibitable-destructive-commands.md
- Query JSON and Array ID Columns with Array-Column Relationshipslaravel/eloquent/laravel-array-column-relationships-hasmanyarraycolumn.md
- Query Relationships Across Multiple Database Connectionslaravel/eloquent/laravel-where-has-multiple-database-connections.md
- Refactor PHP Enum Cases from snake_case to PascalCase with Rectorphp/tooling/php-rector-refactor-enums-pascal-case.md
- Reusable Migration Fields with Custom Blueprint Macroslaravel/eloquent/laravel-blueprint-macro-reusable-schema-audit-fields.md
- Reusable Tappable Scopes for Eloquent and Laravel Scout Querieslaravel/eloquent/laravel-tappable-scopes-eloquent-scout.md
- Reusable whereLike Macro with Relationship and Expression Supportlaravel/eloquent/laravel-custom-wherelike-macro.md
- Reuse Model Instances Across Nested Factories with Factory recycle()laravel/testing/laravel-factory-recycle-existing-models.md
- Skip Expensive CI Steps Using git diff Instead of File Timestampsgit/github-actions/github-actions-skip-steps-with-git-diff.md
- Speed Up Test Suites with the LazilyRefreshDatabase Traitlaravel/testing/laravel-testing-lazily-refresh-database.md
- Stream CSV Downloads in Laravel Without Creating Temporary Fileslaravel/http-api/laravel-stream-csv-downloads-without-temporary-files.md
- Stream CSV Report Downloads with Renderless Livewire Component Actionslivewire/performance/livewire-renderless-export-csv-reports.md
- Stream Large Datasets: cursor() vs lazy() in Eloquentlaravel/eloquent/laravel-cursor-vs-lazy-collections.md
- Streamline Testing with Pest Test Impact Analysis (TIA)pest-php/plugins/pest-tia-plugin-workflow.md
- Test Time Delays Without Slowing Down Tests Using the Sleep Helperlaravel/testing/laravel-sleep-helper-testable-delays.md
- Tick-Based Execution Timeout Wrapper in PHP Without PCNTLphp/performance/php-timeout-guard-ticks-without-pcntl.md
- Trigger a GitHub Actions Workflow Across Repositoriesgit/github-actions/github-actions-cross-repo-workflow-dispatch.md
- Typed Arrays and Array Shapes in PHP with PHPDocphp/tooling/php-array-shapes-phpdoc.md
- UI Controls Are Not Security Layers: Always Enforce Policieslaravel/validation/laravel-security-ui-vs-policy-enforcement.md
- Use CSS Container Queries for Modular Component Layoutscss/styling/css-container-queries-responsive-components.md
- Use Laravel's remember_token as a Revocation Signallaravel/architecture/laravel-remember-token-revocation-signal.md
- Use sole() Instead of firstOrFail() for Single Record Guaranteeslaravel/eloquent/laravel-sole-vs-firstorfail.md
- Why strip_tags() Is Not Enough for XSS Protectionphp/basics/php-security-strip-tags-vs-htmlpurifier.md
- Work Around MySQL Subquery Restrictions on Target Tablesmysql/queries/mysql-subquery-same-table-update-restriction.md
- Write Files Incrementally in Build Scripts to Avoid Unnecessary Rebuildsgit/github-actions/github-actions-incremental-file-writing.md