Laravel 12 : What is new | Laravel 12 updates

Other Blogs

Blogs ❯❯ Laravel

Image could not load

Laravel 12

अगर आप एक PHP developer है, तो Laravel 12 का wait करना natural है ! Laravel 11 ने जो foundation दिया, उस पर Laravel 12 और भी speed, simplicity, और power लेकर आया है।

चलो देखते हैं, इस बार क्या नया है।

1. New way to casting

पहले $casts array use करते थे model में -

protected $casts = [ 'birthday' => 'date', 'metadata' => 'array', ];

अब आप casts() method use कर सकते हो, जो ज़्यादा readable है -

public function casts(): array { return [ 'birthday' => 'date', 'metadata' => 'array', ]; }

2. Default Testing Framework – Pest

Laravel 12 ने Pest को default testing framework बना दिया है। PHPUnit कि जगह, Pest से आप tests लिखने में 50% कम time लगा सकते हो।

test('user can login', function () { $user = User::factory()->create(); $this->post('/login', [ 'email' => $user->email, 'password' => 'password', ])->assertRedirect('/dashboard'); });

Note* Syntax PHPUnit से ज़्यादा simple है, और syntax errors कम होते हैं।

3. Health Route – App Checkup

अब आप अपनी Laravel app का health check एक route से कर सकते हो ! Laravel 12 new php artisan make:health command के साथ आता है, जो एक /health route बनाता है।

जो कुछ important चीज़ें Check करता है -

  • Database connection

  • Redis status

  • Cache driver

  • Disk space

Usage

php artisan make:health

Browser में जाओ https://yourapp.com/health – सब कुछ green दिखेगा तो app fit है :)

4. Eager Loading Improvement

पहले अगर आप with() और load() use करते थे, वो same नहीं थे, Laravel 12 ने with() और load() को sync कर दिया है।

$users = User::with('posts')->get(); $users->load('comments'); // Ab yeh bhi same $users instance par apply hoga!

Advantange : Code confusion कम, और performance better!

5. New Artisan Commands

php artisan make:enum → Enum class बनाये
php artisan make:interface → Interface generate करे
php artisan make:trait → Trait बनाये

Bonus : अब आप custom stubs बना सकते हो हर command के लिए।

Example -

php artisan stub:publish

6. Minimum PHP Version 8.2

Laravel 12 के लिए अब PHP 8.2 चाहिए , इसका मतलब आपको PHP 8.2 के सारे features मिलेंगे जैसे -

  • readonly classes

  • array_is_list() function

  • Randomizer class

7. Routes Cache Improvement

Routes cache (php artisan route:cache) अब 2x faster है, especially large projects में।

Comment करके बताएं : "Laravel 12 का कौन सा feature आपको सबसे पसंद आया ?"

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 5.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook

Your Thought ?

Please wait . . .

    Recent Blogs

    Loading ...

    0 Comment(s) found !