PHP Attributes: Modern Metadata in Your Code

Since PHP 8, we’ve had attributes — a modern way to add metadata directly to classes, methods, or properties. Think of them like annotations in Java or decorators in Python. What are Attributes? Attributes let you “tag” parts of your code with extra information. Frameworks or libraries can then read these tags at runtime and act on them. Example: #[Route('/home', methods: ['GET'])] class HomeController { // ... } Here, the Route attribute describes how this controller should be exposed. ...

September 11, 2025 · 2 min · Hamid

Laravel 10 new features

Finally, Laravel 10 is released. It requires PHP >= 8.1. Most of the features are added by the core Laravel team and not by other contributors, and it seems that there are no big changes compared to previous version releases. Let’s have a glance. New Type Hinting Model Nuno Maduro, creator of Pest, has added a new PHP style of type hinting and removed the old way of doc-block in all stubs and maybe the codebase. It seems that the change does not have a sensible difference for end-users :) ...

February 15, 2023 · 2 min · Hamid

Error types and error reporting in PHP

It is important to know about error types in PHP. With this knowledge, it would be easier to find and solve errors. Basically, we have 4 types of errors in PHP and I will show them to you with examples. 1. Notice PHP is not sure about whether it is an error or not! 2. Warning An error that is important and should be fixed but does not stop code execution. ...

December 4, 2022 · 2 min · Hamid

Mock Config in Laravel

Hi all. If you are testing your application and you need to make your config constant or change it to a specific value for testing, you can mock it simply! The Config facade of Laravel has a method named set() which overwrites the default value of configs like this: Config::set('name', 'Laravel'); So in a testing environment, you can do something like this: public function test_that_home_page_is_working() { Config::set('name', 'Laravel'); $this->get('/')->assertSee("Laravel"); } Generally, Laravel facades have several benefits because of their testability. You can Mock all facades of Laravel easily. Also, if you want to have deeper knowledge about testing tools, you can take a look at PHP Mockery.

September 3, 2022 · 1 min · Hamid

Activate links of Laravel Blade based on current route name

Consider a navigation menu with a bunch of links and you are trying to activate them based on the current active route name. In a normal case, you have to return the currentRouteName() from the controller or maybe in a view composer or any other place. I have written a simple Laravel composer package that makes it a little bit simpler. You can take a look at it here: https://github.com/hamidhaghdoost/active. For installation, use the composer require command like this: ...

May 13, 2022 · 1 min · Hamid