Команда Laravel випустила версію 12.42, яка включає атрибути запитів HTTP-клієнта, підтримку Enums у замінах Translator, методи перевірки індексів у схемах бази даних та багато іншого.
Люк Кузміш запропонував метод withAttributes() для визначення атрибутів даних на екземплярі PendingRequest. Ви можете потім отримати їх за допомогою методу attributes():
$response = Http::withAttributes(['name' => 'first'])
->get('https://example.com/test');
$response->attributes(); // ['name' => 'first']
Деталі реалізації можна знайти у Запиті на злиття #58038.
Хосейн Хосні представив оновлення, яке підтримує Enums у замінах Translator:
$t = new Translator($loader, 'en');
$t->get('string_backed_enum', ['month' => Month::February]);
// Laravel 12 був випущений у :month 2025
// Laravel 12 був випущений у лютому 2025
Деталі реалізації доступні у Запиті на злиття #58048.
Джек Бейліс додав методи whenTableHasIndex та whenTableDoesntHaveIndex для виконання коду в залежності від наявності індексу в таблиці:
use Illuminate\Support\Facades\Schema;
// До
public function up(): void
{
if (! Schema::hasIndex('product', 'name')) {
Schema::table('product', function (Blueprint $table) {
$table->index('name', 'index_name');
});
}
}
// Після
public function up(): void
{
Schema::whenTableHasIndex('product', 'name', function (Blueprint $table) {
$table->index('name', 'index_name');
});
// Ви також можете вказати тип індексу...
Schema::whenTableDoesntHaveIndex('product', 'name', function (Blueprint $table) {
$table->index('name', 'index_name');
}, 'unique');
}
Деталі реалізації знайдете у Запиті на злиття #58005.
Повний список нових функцій та оновлень дивіться нижче, а також порівняння версій 12.41.0 та 12.42.0 на GitHub. Наступні зауваження до випуску взяті прямо з чекліста:
Context::scope() від @cosmastech у https://github.com/laravel/framework/pull/58012required та sometimes для правила Password від @mrvipchien у https://github.com/laravel/framework/pull/58034optional() від @cosmastech у https://github.com/laravel/framework/pull/58027newRequest() до Pool і Batch від @cosmastech у https://github.com/laravel/framework/pull/58038PendingRequest@pool() та batch() від @cosmastech у https://github.com/laravel/framework/pull/57973illuminate/reflections з illuminate/support від @crynobone у https://github.com/laravel/framework/pull/58052.gitattributes до illuminate/reflection від @crynobone у https://github.com/laravel/framework/pull/58055PendingRequest@withRequestContext() від @cosmastech у https://github.com/laravel/framework/pull/58054