Oussama

@oussamamater.bsky.social

I write code.

Laravel Tip 💡: Wrap a Pipeline in a DB Transaction Elegantly If you are using Laravel pipelines and wrapping the whole thing in a DB transaction, since Laravel v12.22 you can simplify your code by just calling "withinTransaction()" on the pipeline 🚀 #laravel

Bild

Laravel Tip 💡: Handle Pluralization Elegantly Did you know that besides localization, Laravel also handles pluralization out of the box? When you have messages in different plural forms, you can define them all at once and use ranges to choose the right format 🚀 #laravel

Bild

Laravel Tip 💡: Detect User Language Laravel uses Symfony's HttpFoundation component, which comes with some nice goodies. If you are working with localization and need to detect the user's preferred language, you can just call "getPreferredLanguage" 🚀 #laravel

Bild

Laravel Tip 💡: Better If Statements in Blade If you are working with Blade, you will almost certainly use an if statement, and chances are, there is already a shortcut directive for what you need 🚀 #laravel

Bild

Laravel Tip 💡: The New "whereAttachedTo" Method We have all used "whereHas", and sometimes you need to constrain it to match specific models. Since Laravel v12.13, you can use "whereAttachedTo" for exactly that 🚀 #laravel

Bild

Laravel Tip 💡: Date Checks with Carbon I know you've had to check if a date has expired or is in the future at least once. Since Laravel uses Carbon under the hood, you've got access to a ton of helpers to handle all that elegantly 🚀 #laravel

Bild

Laravel Tip 💡: Select Sub-Arrays There will be times when you need to extract a sub-array from the main one, whether it's from a JSON response, your models, or whatever. While you could use map for that, Laravel ships with a much more elegant helper, "select", just for this 🚀 #laravel

Bild

Laravel Tip 💡: Clamp Numbers Have you ever needed to keep a number within a specific range, like a rating or a computed value? While you can hack your way through with min and max, Laravel ships with an elegant helper "clamp" to do exactly that 🚀 #laravel

Bild

Laravel Tip 💡: Global Middleware for Jobs Did you know you can apply global job middleware? It can be really useful for custom logging and monitoring, like instantly notifying Slack or Discord about slower-than-usual jobs 🚀 #laravel

Bild

Laravel Tip 💡: The "forelse" Blade Directive When looping over a collection, you have probably checked its count first to handle the empty state. But the "forelse" Blade directive has existed forever, and it does exactly that, elegantly 🚀 #laravel

Bild

Laravel Tip 💡: Record API Responses as Fixtures If you are testing your API integrations (which you should) you are probably using the "fake()" method. To quickly prepare a stub for testing, you can use the "sink()" method to save the response into a fixture 🚀 #laravel

Bild

Laravel Tip 💡: Display Remaining Attempts for a Rate-Limited Job If you have a rate-limited job that can be dispatched via a UI, you can greatly improve the UX by displaying how many attempts are remaining for the day 🚀 #laravel

Bild

Laravel Tip💡: Fail Jobs on Specific Exceptions Ever needed to fail a job for specific exceptions and had to use a try-catch with "fail()"? Since Laravel v12.19, you can do it more elegantly with the new "InvalidContentFormatException" middleware 🚀 #laravel

Bild

Laravel Tip 💡: Real-Time Download Progress If you ever need to download a file in your Laravel app, consider using Guzzle's progress option. It gives you real-time updates on the download, which you can broadcast to your UI, display in the console, or handle however you like 🚀 #laravel

Bild

Laravel Tip 💡: Confirm to Proceed Need to confirm before running a command? Laravel ships with the "ConfirmableTrait" for that exactly. Just call "confirmToProceed()" for confirmation, and skip the prompt anytime with the "--force" option 🚀 #laravel

Bild

Laravel Tip 💡: Use Contextual Attributes You've probably had to initialize attributes with config values before. Laravel v11 makes it easier with contextual attributes. You can inject values directly, use constructor property promotion, and skip the boilerplate. It's just #laravel

Bild

Laravel Tip 💡: HTTP Response Status Helpers When making API requests, you often need to check the response status code. While you can do this manually, Laravel provides wrappers for almost all status codes, which you can use for elegant and readable checks 🚀 #laravel

Bild

Making Laravel Horizon suck less with an MCP server — delete failed jobs, figure out what went wrong, see job stats, and more. Basically, all the things Horizon is missing 🤖

PHP Tip 💡: Better Custom Exceptions Do you use custom exceptions in your codebase and end up with multiple empty classes? You can group all related exceptions into a single class and use static methods to create english-like code that immediately tells you what went wrong 🚀 #php

Bild

Laravel Tip 💡: Wrap Configs in Classes Laravel configs often get reused across the codebase, which can become painful to manage. Instead, group related configs in a class for cleaner, easier maintenance 🚀 #laravel

Bild

Laravel Tip 💡: Reusable Pipelines Pipelines allow you to split a large task into smaller, more manageable ones. Sometimes, you may want to use the same pipeline in different places, and it turns out Laravel allows you to define reusable pipelines out of the box 🚀 #laravel

Bild

Laravel Tip 💡: Control Notification Delivery There are times when you may need to determine whether a queued notification should be sent to the user, such as when users can opt out of notifications. Laravel ships with the "shouldSend" to do exactly that 🚀 #laravel

Bild

Laravel Tip 💡: Prompt for Missing Arguments Have you ever needed to ensure users provide the required console arguments? Laravel ships with the "PromptsForMissingInput" contract to automatically prompt the user for missing input 🚀 #laravel

Bild