Tags

Here is all articles with best practice tag

How to Get a PHP Enum Case from Its Value
best practice
August 26, 2026 8 minutes reading time

How to Get a PHP Enum Case from Its Value

PHP enums provide a clean way to represent a fixed set of possible values. When working with a backed enum, each enum case has an associated scalar value, such as a string or integer. A common situation is receiving a value from a database, API request, form, or another external source and needing to retrieve […]

How To Remove a String Prefix Easily In Laravel
best practice
August 10, 2026 8 minutes reading time

How To Remove a String Prefix Easily In Laravel

Laravel provides many useful string helpers through the Illuminate\Support\Str class. One of them is Str::chopStart(), which makes it easy to remove a specific string from the beginning of another string. It is especially useful when working with prefixes such as URL paths, file names, namespaces, or other formatted strings. # What Is Str::chopStart() in Laravel? […]

PHP final classes
best practice
July 13, 2026 8 minutes reading time

PHP final classes

Object-oriented programming in PHP gives developers powerful inheritance features. However, not every class is designed to be extended. That’s where the final keyword comes in. A final class explicitly tells PHP that this class cannot be inherited. It protects the class from being extended and helps preserve its intended behavior. When you declare a class […]

Laravel #[CurrentUser] Attribute
best practice
July 7, 2026 8 minutes reading time

Laravel #[CurrentUser] Attribute

Starting with Laravel 12, Laravel introduced the #[CurrentUser] attribute, making it easier to access the authenticated user inside controller methods. Instead of retrieving the user manually using Request object or auth() helper, you can now ask Laravel to inject the authenticated user directly into your method. This results in cleaner, more readable controller code while […]

Laravel $this->columnName vs $this->attributes[‘columnName’]
best practice
June 21, 2026 8 minutes reading time

Laravel $this->columnName vs $this->attributes[‘columnName’]

When working with Eloquent models in Laravel, you may have seen both of these approaches used to access model attributes: Although they may seem identical, they behave differently under the hood. Understanding the difference is especially important when creating custom accessors, mutators, casts, and model attributes. # Quick Answer The main difference is $this->columnName passes […]

Laravel Bulk Update vs Save: Why Observer Events Are Not Triggered
best practice
June 6, 2026 8 minutes reading time

Laravel Bulk Update vs Save: Why Observer Events Are Not Triggered

When working with Laravel, performance is often a major concern. One common optimization is using bulk updates instead of loading and updating models one by one. However, there is an important behavior that many developers overlook: Laravel Observer events are not triggered when using bulk update queries. If your application relies on observers for logging, […]

PUT vs PATCH in REST API: What’s the Difference?
best practice
May 27, 2026 8 minutes reading time

PUT vs PATCH in REST API: What’s the Difference?

Many developers confuse PUT and PATCH in REST APIs. Both are used for updating data, but they work differently. #PUT Method PUT is used to replace an entire resource. Example: With PUT, you usually send all fields because the old resource is replaced by the new one. #PATCH Method PATCH is used for partial updates. […]

Clean Up Your Blade Templates with Laravel’s $loop Variable
best practice
May 8, 2026 8 minutes reading time

Clean Up Your Blade Templates with Laravel’s $loop Variable

If you work with Laravel Blade templates, one feature that can make your views much cleaner is the built-in $loop variable inside the @foreach directive Many developers manually create counters or extra conditions inside loops, while Laravel already provides a powerful helper for this. Here’s a simple example: In this example, $loop->iteration gives you the […]

Controller Naming in MVC
best practice
May 2, 2026 8 minutes reading time

Controller Naming in MVC

Confused about naming your controllers? You’re not alone !! Sometimes you may hesitate when naming controllers in Laravel:should it be singular or plural? According to Laravel best practices, controllers should be named in singular form. Recommended examples: Not recommended examples: Laravel follows a clear and predictable pattern: #Why Singular? A controller represents a resource, not […]

How to Edit a Git Commit Message After Push
best practice
April 27, 2026 8 minutes reading time

How to Edit a Git Commit Message After Push

If you’ve been working with Git for a while, you’ve probably experienced this: You commit your changes, push them to the remote repository… and then notice a typo in your commit message 😑 It might seem like a small issue, but in professional projects, clean and meaningful commit messages are part of best practices just […]