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鈥檚 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

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