The source of programming articles
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 […]
In PHP, you can create a reference to a variable using the & operator. A reference means that two variables point to the same value, so changing one variable can also affect the other. Here is an example of creating reference in PHP. In the code below $b is a reference to $a, means if […]
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? […]
Have you ever run chmod on a folder or file in Linux, only to open git status and see a long list of modified files, even though you didn’t change a single line of code? This is a common frustration for developers working with any project on Linux. Git is tracking file permission changes (the […]
SQL injection is one of the oldest and most dangerous security vulnerabilities in web applications. If you’re building applications with Laravel, you may wonder: Does Laravel automatically protect against SQL injection, or do I need to implement additional security measures? The short answer is yes Laravel provides strong built-in protection against SQL injection when you […]
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 […]
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 […]
If you frequently start new projects, you’ve probably found yourself copying an existing project over and over again.Maybe you have a Laravel starter kit, a Node.js boilerplate, a PHP project structure, or simply a repository containing your preferred folders, configurations, and development tools. Instead of cloning a project and cleaning it up every time, GitHub […]
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’s event system is one of the framework’s most powerful features. However, there is a subtle issue that can cause your event listeners to execute twice when you manually define listener execution order in your EventServiceProvider. If you’ve ever noticed duplicate emails, repeated notifications, or the same logic running twice, this might be the reason. […]