Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
4 snippets tagged #laravel-11 · Show all
PHP
October 10, 2026
Laravel Cache::flexible stale-while-revalidate caching
Serves the cached value instantly, even after it goes stale, and refreshes it in the background after the response is sent. Use it for slow queries on busy page...
<?php
use Illuminate\Support\Facades\Cache;
PHP
October 10, 2026
Laravel Concurrency::run execute tasks in parallel
Runs several closures at the same time and returns their results in order. Use it when a page needs independent slow calls, such as two reports or two APIs, and...
<?php
use Illuminate\Support\Facades\Concurrency;
PHP
October 10, 2026
Laravel Context facade add data to every log entry
Stores values once and attaches them to all later log entries in the request, and to queued jobs dispatched from it. Use it for a request or trace ID so you can...
<?php
use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\Log;
PHP
October 10, 2026
Laravel Number helper format numbers as 1.2K, 3M, file sizes
Built-in formatting for abbreviations, currency, file sizes and percentages, so you don’t need to write helpers. Use it in views and API responses. Needs Larave...
<?php
use Illuminate\Support\Number;