Laravel 11 Yenilikleri: Modern PHP Framework Rehberi
zafer ak
Yazar
Laravel 11 Neler Getiriyor?
Laravel 11, Mart 2024'te yayınlandı ve PHP 8.2+ gerektiriyor. Minimal yapı, yeni araçlar ve performans iyileştirmeleri ile geliyor.
Minimal Application Structure
Laravel 11 varsayılan olarak çok daha az dosyayla başlıyor:
- Kernel dosyaları kaldırıldı (HTTP, Console)
- Middleware app/Http/Middleware'den bootstrap/app.php'ye taşındı
- Exception handler basitleştirildi
- Service provider sayısı azaltıldı
bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
MyCustomMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
Per-Second Rate Limiting
RateLimiter::for('api', function (Request $request) {
return Limit::perSecond(1)->by($request->user()?->id ?: $request->ip());
});
Health Routing
->withRouting(
web: __DIR__.'/../routes/web.php',
health: '/up',
)
/up endpoint'i otomatik olarak 200 OK döner, load balancer health check için ideal.
Yeni Artisan Komutları
# Tüm sınıfları tek komutla oluştur
php artisan make:class ClassName
# Interface oluştur
php artisan make:interface InterfaceName
# Enum oluştur
php artisan make:enum StatusEnum
# Trait oluştur
php artisan make:trait TraitName
Deferrable Provider Loading
Service provider'lar artık lazy-load edilebilir:
class MyServiceProvider extends ServiceProvider
{
public function provides(): array
{
return [MyService::class];
}
}
Model Casts Değişikliği
// Laravel 10
protected $casts = [
'options' => 'array',
];
// Laravel 11 - Method olarak
protected function casts(): array
{
return [
'options' => 'array',
'secret' => 'encrypted',
];
}
Once Helper
function expensiveOperation() {
return once(function () {
// Bu kod aynı request'te sadece 1 kez çalışır
return DB::table('users')->count();
});
}
Laravel 10'dan Geçiş
- PHP 8.2+ güncellemesi
- composer.json Laravel versiyonunu güncelle
- Kernel dosyalarını bootstrap/app.php'ye taşı
- Deprecated özellikleri kaldır
- Test suite'ini çalıştır
Sonuç
Laravel 11, framework'ü daha minimal ve modern hale getiriyor. Yeni projeler için ideal, mevcut projeler için dikkatli geçiş planlaması gerekli.