Laravel 12 Features Review and Installation Example

Recently laravel has launched it's latest version  laravel 12 with awesome features along with developer friendly starter kit. Here in this article we will install laravel 12 and go through latest features. Stay with with article. Hope that , you will get clear ideas

Create Fresh Empty Laravel 12 Project

As we are dealing with laravel 12 so we need to create  project using laravel 12 version. For this we can run below composer create project command to create a new laravel 12 project. Although we can install using laravel global installer

composer create-project --prefer-dist laravel/laravel laravel12-project
If you want to install using laravel global installer then you need to run below two command

composer global require laravel/installer
laravel new laravel12-project

If you are mac user and want to install in herd then visit laravel official page 

Laravel 12 Installation in Terminal with Log

laravel 12 Installation - programmingmindset.com


After successful installation and running server laravel 12 will be started. It will appear with new welcome page. Here is the welcome page screenshot

laravel 12 Installation - programmingmindset.com

Installation is Complete. Now let's go to features and upgrades. 

1 - Dependency Injection Upgrade

If you look laravel has introduced newer way of dependency injection. Here is the example code

Old :

class UserController
{
    protected $service;
    public function __construct(RoleManagementService $service)
    {
        $this->service = $service;
    }
}

New:

class UserController
{
    public function __construct(protected RoleManagementService  $service) {}
}

2 - Performance Upgrade

Performance plays an important role in modern web applications, particularly for high-traffic applications. Laravel 12 brings significant improvements with advanced cache mechanisms, support for asynchronous processing, and better integration of modern PHP benefits. 

It has added new asyncRemember method for caching feature

Old:

use Illuminate\Support\Facades\Cache;

// Caching a role
$role = Cache::remember('role_cache_'.$id, 600, function () use ($id) {
    return Role::find($id);
});

New:

use Illuminate\Support\Facades\Cache;
// Utilizing the new async caching API
$role = Cache::asyncRemember('role_cache_'.$id, 600, function () use ($id) {
    return Role::find($id);
});

3 - Nesbot Carbon Package Upgrade

Laravel 12 has official switched to carbon version 3. Carbon 3 provides awesome new features. You can easily use carbon 3 features inside your laravel 12 application. For your kind information Nesbot/Carbon is so much popular for handing date and time.

4 - Debugging Tools Enhancement

Laravel old debugging methods depend on basic dumps or external tools, which might be time-killer while debugging. The new introduced debug method is integrated in core framework and it will help by recommendations

Old:

dd($variable);

New:

debug($variable)->suggest();

Read also: Real time notification using reverb laravel 11

Read also: Block specific ip addresses using laravel 11 middleware

5 - Password Validation Improvement

Laravel has added new method secureValidate in it's laravel 12 version. Here is the implementation 

Old:

$request->validate(['password' => 'required|min:8']);

New:

$request->secureValidate(['password' => 'required|min:8|strong']);

6 - Laravel Api Version Feature

Laravel 12 also has given attention to api versioning while developing api.

Old:

Route::get("v1/posts", [PostController::class, "index"]);

New:

Route::apiVersion(1)->group(function() {
    Route::get("posts", [PostController::class, "index"]);
});

7 - Laravel Starter Kits

Laravel 12 has introduced starter kits for easy ui integration in laravel. You don't need to think regarding frontend, laravel has already starter kits. These kits will give you flexibility to integrate frontend js libraries easily. Here are lists for starter kits 

  1. React
  2. Vue
  3. LiveWire

Hope that, this article has given you clear idea regarding laravel 12 features. If you find this article helpful then you can read regular blog from here 

Tags: