Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.
7 min read
Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.
We had the pleasure of attending Laracon US this year, and we were blown away by the ambitious projects that Taylor Otwell and the Laravel core team have introduced. It’s always exciting to see the innovation happening in the Laravel ecosystem, and we can’t resist to spread a word among our fellow Laravel developers about some cool new updates.
One announcement that really stood out to us was the introduction of some exciting new open-source features for the Laravel Framework. After taking some time to let it all sink in, we’re ready to share our thoughts here with you. Here we go!
Ever wished your application could respond faster? The new defer() function lets you postpone certain tasks until after the user receives the response. This keeps your app feeling lightning-quick!
You can use defer() to delay functions that don't need to run immediately. For example, reporting metrics or sending emails.
use App\Services\Metrics;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use function Illuminate\Support\defer;
Route::post('/orders', function (Request $request) {
// Process the order...
$order = Order::create($request->all());
// Defer the metrics reporting
defer(fn () => Metrics::reportOrder($order));
return response()->json($order);
});
In this example, the user gets their order confirmation without waiting for the metrics to be reported. Neat, right?
Caching can be tricky, especially when cached data expires, and users experience delays. The new Cache::flexible method introduces a smart solution by serving cached data while refreshing it in the background.
The flexible method accepts an array with two values:
Fresh period: How long the cache is considered fresh.
Stale period: How long stale data can be served.
$value = Cache::flexible('users', [300, 600], function () {
return DB::table('users')->get();
});
For the first 5 minutes (300 seconds), the data is fresh.
Between 5 and 10 minutes, stale data is served, and the cache refreshes in the background.
After 10 minutes, new data is fetched immediately.
This keeps your app responsive while ensuring data is up-to-date.
Need to run multiple tasks at the same time? The new Concurrency facade lets you execute closures concurrently, boosting your app's performance. It's like having multiple hands to get the job done
Here's how you can run tasks concurrently:
use Illuminate\Support\Facades\Concurrency;
use Illuminate\Support\Facades\DB;
[$userCount, $orderCount] = Concurrency::run([
fn () => DB::table('users')->count(),
fn () => DB::table('orders')->count(),
]);
Both tasks run simultaneously, reducing the total execution time.
You can also defer concurrent tasks to run after the response is sent:
use App\Services\Metrics;
use Illuminate\Support\Facades\Concurrency;
Concurrency::defer([
fn () => Metrics::report('users'),
fn () => Metrics::report('orders'),
]);
This is perfect for tasks that don't need to complete before the user gets a response.
Good news! You can now generate temporary, signed URLs for files stored locally. This is great for securely sharing files without exposing their actual paths.
First, ensure your local disk supports serving files:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'serve' => true,
],
use Illuminate\Support\Facades\Storage;
$url = Storage::temporaryUrl(
'invoices/receipt.pdf', now()->addMinutes(15)
);
Writing conditional attributes in Blade just got easier! The when helper simplifies your templates by conditionally adding attributes.
Instead of writing long conditional statements, you can do this:
<div {{ when($isActive, 'class=”active”') }}>
<!-- Content here -->
</div>
If $isActive is true, the class="active" attribute is added. Otherwise, it's skipped. Simple and clean!
The query builder now has a firstOrFail method, similar to Eloquent's. This means you can fetch the first record or throw an exception if none is found.
$user = DB::table('users')->where('email', $email)->firstOrFail();
No more checking for null values—handle exceptions as needed.
Need to skip a queued job based on certain conditions? The new Skip middleware lets you do just that without cluttering your handle method.
Add the Skip middleware to your job:
use Illuminate\Queue\Middleware\Skip;
public function middleware()
{
return [
Skip::when($this->shouldSkip()),
];
}
protected function shouldSkip()
{
// Your condition here
return $this->attempts() > 3;
}
If shouldSkip() returns true, the job is skipped.
Logging is super important, but let’s be honest, the global info() method can feel a little... That’s why Laravel 11 now gives you a namespaced log function to keep your logging tidy and organized! 🙌
Now you can log with style by using the log() function in your custom namespace:
use function Illuminate\Log\log;
log('User has been successfully created.');
These new Laravel features are designed to make your development experience smoother and your applications faster. We can't wait to see what you'll build with them!
While we are at it, we also specialize in Laravel development, so if you’d like to learn more about what we can offer and what Laravel development services we can provide, feel free to check out our dedicated page - we’re here and ready to chat.
We are a 200+ people agency and provide product design, software development, and creative growth marketing services to companies ranging from fresh startups to established enterprises. Our work has earned us 100+ international awards, partnerships with Laravel, Vue, Meta, and Google, and the title of Georgia’s agency of the year in 2019 and 2021.