Laravel 11 Yenilikler: Modern PHP Framework
zafer ak
Yazar
Laravel 11, Mart 2024'te yayınlandı ve PHP 8.2 minimum gereksinimi ile birlikte birçok yenilik sunuyor.
Streamlined Application Structure
Laravel 11, daha minimal bir uygulama yapısı sunuyor:
# Kaldırılan dosyalar:
- app/Http/Kernel.php
- app/Console/Kernel.php
- app/Providers/ (çoğu)
- Çoğu middleware dosyası
# Yeni yapı:
app/
├── Http/
│ └── Controllers/
├── Models/
└── Providers/
└── AppServiceProvider.php
bootstrap/
├── app.php
└── providers.php
routes/
├── web.php
├── console.php
└── api.php (opsiyonel)
Bootstrap/app.php
Tüm uygulama yapılandırması tek dosyada:
<?php
// bootstrap/app.php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
\App\Http\Middleware\CustomMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->reportable(function (Throwable $e) {
// Özel exception handling
});
})->create();
Laravel Reverb
First-party WebSocket server:
# Kurulum
composer require laravel/reverb
php artisan reverb:install
# Başlatma
php artisan reverb:start
# config/reverb.php
return [
'servers' => [
'reverb' => [
'host' => env('REVERB_HOST', '0.0.0.0'),
'port' => env('REVERB_PORT', 8080),
],
],
];
Per-Second Rate Limiting
<?php
// Laravel 10
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60);
});
// Laravel 11 - saniye bazlı
RateLimiter::for('api', function (Request $request) {
return Limit::perSecond(10);
});
// Route'ta kullanım
Route::middleware('throttle:api')->group(function () {
Route::get('/users', [UserController::class, 'index']);
});
Health Routing
<?php
// bootstrap/app.php
->withRouting(
web: __DIR__.'/../routes/web.php',
health: '/up', // Load balancer health check
)
// /up endpoint otomatik olarak 200 döner
// Kubernetes, AWS ELB için ideal
Graceful Encryption Key Rotation
# .env
APP_KEY=base64:yeni_anahtar
APP_PREVIOUS_KEYS=base64:eski_anahtar1,base64:eski_anahtar2
# Eski anahtarlarla şifrelenmiş veriler okunabilir
# Yeni veriler yeni anahtar ile şifrelenir
Yeni Artisan Komutları
# API routes dosyası oluşturma
php artisan install:api
# Broadcasting kurulumu
php artisan install:broadcasting
# Middleware oluşturma
php artisan make:middleware CustomMiddleware
# Class oluşturma
php artisan make:class Services/PaymentService
# Enum oluşturma
php artisan make:enum Status
# Interface oluşturma
php artisan make:interface PaymentGateway
# Trait oluşturma
php artisan make:trait HasUuid
Dusk Improvements
<?php
// Chrome driver otomatik yönetimi
// chrome-driver paketi gerekli değil
// tests/DuskTestCase.php
protected function driver(): RemoteWebDriver
{
return RemoteWebDriver::create(
'http://localhost:9515',
DesiredCapabilities::chrome()
);
}
Casts Improvements
<?php
// casts() metodu ile daha esnek tanımlama
class User extends Model
{
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'options' => AsEnumCollection::of(UserOption::class),
];
}
}
Sonuç
Laravel 11, daha minimal ve modern bir yapı sunarak geliştirici deneyimini iyileştiriyor. Reverb ile native WebSocket desteği, production uygulamaları için büyük avantaj sağlıyor.