আমি রিয়াজুল, ল্যারাভেল নিয়ে কাজ করছি ২০১৪ (v4.2) সাল থেকে যখন লারাভেল একদম শুরুর দিকে ছিল। সেই তখন থেকে লারাভেল এর পরিবর্তনগুলো চোখের সামনে দেখা। দেখতে দেখতে ১২ চলে এসেছে। এ পর্যন্ত যতগুলো ল্যাঙ্গুয়েজ এর ফ্রেমওয়ার্ক এক্সপ্লোর করেছি তার মধ্যে সবচেয়ে বেশি ডেভেলপার ফ্রেন্ডলি হচ্ছে লারাভেল।
Laravel 12 এসেছে আরও modern, clean ও robust development experience নিয়ে। প্রতি major release-এর মতো এবারও Laravel অনেক গুরুত্বপূর্ণ পরিবর্তন এনেছে, যা developer productivity এবং code quality বাড়াবে।
নিচে Laravel 12-এর গুরুত্বপূর্ণ নতুন ফিচার ও পরিবর্তনসমূহ উদাহরণসহ তুলে ধরা হলো।
১. Strict Type Hinting in Controllers
Laravel 12-এ এখন controller method-এ type hint না থাকলে সেটি কাজ করবে না। অর্থাৎ, type-hinting এখন বাধ্যতামূলক।
উদাহরণ:
// routes/web.php
Route::get('/user/{user}', [UserController::class, 'show']);
// app/Http/Controllers/UserController.php
public function show(User $user): View
{
return view('user.profile', compact('user'));
}
আগে User $user
না দিলেও Laravel এটি resolve করতে পারত, এখন এটি strict requirement।
২. declare(strict_types=1);
Throughout the Codebase
Laravel 12 এখন সম্পূর্ণভাবে PHP strict types ব্যবহার করে। এর মানে:
- Variable/parameter-এর ভুল টাইপে runtime এ error পাওয়া যাবে।
- Code এর readability ও stability বাড়বে।
declare(strict_types=1);
৩. নতুন laravel new --kit
কমান্ড
Laravel 12-এ এখন নতুন একটি Full-stack starter kit যুক্ত হয়েছে।
laravel new project-name --kit
এটি নিচের টেকনোলজি সহ একটি setup তৈরি করে:
- Inertia.js
- Vue 3
- Tailwind CSS
- Vite
- Authentication scaffold
৪. Enum-based Auth Guards
Authentication guard গুলোর জন্য এখন enum ব্যবহার করা যায়, যা টাইপ-সেইফ এবং ক্লিন।
enum AuthGuard: string
{
case Web = 'web';
case Api = 'api';
}
// ব্যবহার:
Auth::guard(AuthGuard::Api->value)->check();
৫. Cleaner bootstrap/app.php
File
Laravel 12-এ bootstrap/app.php
এখন আরও clean ও expressive।
Laravel 11:
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
Laravel 12:
return Illuminate\Foundation\Application::configure(basePath: dirname(__DIR__))
->withRouting(using: App\Providers\RouteServiceProvider::class)
->withHttpKernel(App\Http\Kernel::class)
->create();
৬. artisan serve
Deprecation
Laravel 12-এ php artisan serve
পুরোপুরি তুলে দেওয়া হয়েছে। এখন prefer করা হচ্ছে:
symfony serve
# অথবা
./vendor/bin/sail up
৭. Improved assertExactJson()
Test assertions এখন JSON key order ও structure match করবে।
$response->assertExactJson([
'name' => 'Reazul',
'email' => 'reazul@example.com',
]);
Key এর order না মিললে test ব্যর্থ হবে। এটি test reliability বাড়ায়।
৮. Rate-limited Exception Logging
Exception log গুলোর জন্য এখন rate limit define করা যায়।
// config/logging.php
'rate_limit_exceptions' => [
\App\Exceptions\CustomException::class => 5, // প্রতি মিনিটে সর্বোচ্চ ৫বার
],
৯. Smarter whenCounted()
Helper
whenCounted()
এখন আরও বেশি intelligent, এবং aggregated data-এর ভিত্তিতে কাজ করে।
$users = User::withCount('posts')->get();
$users->each(function ($user) {
$user->whenCounted('posts', function ($count) {
if ($count > 0) {
// do something
}
});
});
১০. Better Stateful Testing with actingAs()
Test এ actingAs()
এখন আরও seamless।
$this->actingAs(User::factory()->create())
->get('/dashboard')
->assertOk();
Laravel 12 modern PHP practices কে follow করে আরও powerful ও developer-friendly framework হয়ে উঠেছে। টাইপ সেফটি, কোড ক্লিননেস এবং productivity বৃদ্ধির জন্য এই রিলিজটি অত্যন্ত গুরুত্বপূর্ণ।
Laravel 12 নিয়ে আরও জানুন:
Laravel Release Notes - Official Website