The Laravel team released v12.16.0, with an AsUri
model cast, contextual service container binding using PHP 8 attributes, and more:
AsUri Model Cast
Ash Allen contributed a AsUri
model cast that casts values to and from a Illuminate\Support\Uri
instance.
use Illuminate\Support\Uri;use Illuminate\Database\Eloquent\Casts\AsUri; protected function casts(): array{ return [ // ... 'destination_url' => AsUri::class, ];} // Set a URL$shortUrl->destination_url = new Uri('https://www.example.com:1234/hello?param=value');$shortUrl->save();
Contextual Interface Binding via Attributes
Yitz Willroth contributed a Give
attribute that enables contextual dependencies using PHP 8 attributes:
// Traditional approach - in ServiceProvider$this->app->when(UserController::class) ->needs(UserRepositoryInterface::class) ->give(DatabaseUserRepository::class); use Illuminate\Container\Attribute\Give; // Using the Give attributeclass UserController extends Controller{ public function __construct( #[Give(DatabaseUserRepository::class)] private UserRepositoryInterface $userRepository ) {}} // Another exampleclass OrderService{ public function __construct( #[Give(StripePaymentProcessor::class)] private PaymentProcessorInterface $processor ) {}}
See Pull Request #55904 for details.
Add reorderDesc() to Query Builder
Rihulfa Akbar contributed a reorderDesc()
method to the query builder which is a shortcut to add a descending reorder clause to the query:
// using reorder()$this->reorder($column, 'desc'); // reorderDesc()$query->reorderDesc($column);
Assert Redirect Back Backported to Laravel 11
Graham Campbell contributed backporting assertRedirectBack()
which was contributed to Laravel in v12.13:
$testResponse->assertRedirectBack();
Release notes
You can see the complete list of new features and updates below and the diff between 12.16.0 and 12.17.0 on GitHub. The following release notes are directly from the changelog:
v12.17.0
- [11.x] Backport
TestResponse::assertRedirectBack
by @GrahamCampbell in https://github.com/laravel/framework/pull/55780 - Add support for sending raw (non-encoded) attachments in Resend mail by @Roywcm in https://github.com/laravel/framework/pull/55837
- [12.x] chore: return Collection from timestamps methods by @calebdw in https://github.com/laravel/framework/pull/55871
- [12.x] fix: fully qualify collection return type by @calebdw in https://github.com/laravel/framework/pull/55873
- [12.x] Fix Blade nested default component resolution for custom namespaces by @daniser in https://github.com/laravel/framework/pull/55874
- [12.x] Fix return types in console command handlers to void by @michaelnabil230 in https://github.com/laravel/framework/pull/55876
- [12.x] Ability to perform higher order static calls on collection items by @daniser in https://github.com/laravel/framework/pull/55880
- Adds Resource helpers to cursor paginator by @jsandfordhughescoop in https://github.com/laravel/framework/pull/55879
- Add reorderDesc() to Query Builder by @ghabriel25 in https://github.com/laravel/framework/pull/55885
- [11.x] Fixes Symfony Console 7.3 deprecations on closure command by @crynobone in https://github.com/laravel/framework/pull/55888
- [12.x] Add
AsUri
model cast by @ash-jc-allen in https://github.com/laravel/framework/pull/55909 - [12.x] feat: Add Contextual Implementation/Interface Binding via PHP8 Attribute by @yitzwillroth in https://github.com/laravel/framework/pull/55904
- [12.x] Add tests for the
AuthenticateSession
Middleware by @imanghafoori1 in https://github.com/laravel/framework/pull/55900 - [12.x] Allow brick/math ^0.13 by @jnoordsij in https://github.com/laravel/framework/pull/54964
- [12.x] fix: Factory::state and ::prependState generics by @calebdw in https://github.com/laravel/framework/pull/55915