Команда Laravel випустила версію v12.16.0, в якій додали каст AsUri
, прив’язку контекстних сервісів за допомогою атрибутів PHP 8 та багато іншого:
Ash Allen додав каст AsUri
, який перетворює значення з і в екземпляр Illuminate\Support\Uri
.
use Illuminate\Support\Uri;
use Illuminate\Database\Eloquent\Casts\AsUri;
protected function casts(): array
{
return [
// ...
'destination_url' => AsUri::class,
];
}
// Встановлення URL
$shortUrl->destination_url = new Uri('https://www.example.com:1234/hello?param=value');
$shortUrl->save();
Yitz Willroth додав атрибут Give
, який дозволяє використовувати контекстні залежності з атрибутами PHP 8:
// Традиційний підхід - у ServiceProvider
$this->app->when(UserController::class)
->needs(UserRepositoryInterface::class)
->give(DatabaseUserRepository::class);
use Illuminate\Container\Attribute\Give;
// Використання атрибуту Give
class UserController extends Controller
{
public function __construct(
#[Give(DatabaseUserRepository::class)]
private UserRepositoryInterface $userRepository
) {}
}
// Інший приклад
class OrderService
{
public function __construct(
#[Give(StripePaymentProcessor::class)]
private PaymentProcessorInterface $processor
) {}
}
Деталі дивіться у Pull Request #55904.
Rihulfa Akbar реалізував метод reorderDesc()
для побудови запитів, що дозволяє швидко додавати умову перестановки у зворотному порядку:
// використовуючи reorder()
$this->reorder($column, 'desc');
// reorderDesc()
$query->reorderDesc($column);
Graham Campbell переніс метод assertRedirectBack()
, який був доданий у Laravel у v12.13:
$testResponse->assertRedirectBack();
Ви можете переглянути повний список нових функцій та оновлень нижче, а також різницю між версіями 12.16.0 і 12.17.0 на GitHub. Наступні примітки до випуску взято з журналу змін:
TestResponse::assertRedirectBack
від @GrahamCampbell в https://github.com/laravel/framework/pull/55780AsUri
моделі від @ash-jc-allen в https://github.com/laravel/framework/pull/55909AuthenticateSession
від @imanghafoori1 в https://github.com/laravel/framework/pull/55900