The Laravel team released v12.15.0, with Locale-aware number parsing, a string hash()
helper method, inject contextual attribute values, and more:
Locale-aware Number Parsing
Mbungu Ngoma contributed three methods to the Number
class to parse a localized number string to its numeric value. These methods use the Intl extension's NumberFormatter class to parse and define the format type:
use Illuminate\Support\Number; Number::parse($string);Number::parseInt($string);Number::parseFloat($string); // Pass localeNumber::parseFloat(string: $string, locale: 'de'); // It is also possible to pass the type to the parse methodNumber::parse( string: $string, type: NumberFormatter::TYPE_INT64, locale: 'de',);
See Pull Request #55725 for details.
Default Option When Retrieving an Enum
@elbojoloco contributed by passing a default Enum option when retrieving an enum via the InteractsWithData.php trait. For example, this update includes classes like Request
:
// Before$chartType = request()->enum('chart_type', ChartTypeEnum::class) ?: ChartTypeEnum::Bar; // After$chartType = request()->enum('chart_type', ChartTypeEnum::class, ChartTypeEnum::Bar);
TestResponse method to Assert a Client Error
@shane-zeng contributed the assertClientError()
method on a test response:
// Before$this->assertTrue($response->isClientError()); // After$response->assertClientError();
hash
Helper Method
String Istiak Tridip contributed a hash()
method to the Stringable
class to simplify fluent string hashing:
$appId = str('secret-unique-key') ->hash('xxh3') ->take(10) ->prepend('app-');// app-0fb8aac18c
Before Laravel v12.15 you might use the ->pipe()
method, which hash()
simplifies for this use-case:
// Before you would pipe the string to the hash method manually$appId = str('secret-unique-key') ->pipe(fn(Stringable $str) => hash('xxh3', (string) $str)) ->take(10) ->prepend('app-');
See Pull Request #55767 for implementation details.
current_page_url
to the Paginator
Add Mario Juárez contributed adding current_page_url
to the Paginator:
$paginator->toArray()['current_page_url'];
Assert Redirect to Action
Volodya Kurshudyan contributed an assertRedirectToAction()
method to assert a response redirects to a specific controller action:
$this->get('redirect-to-index') ->assertRedirectToAction([TestActionController::class, 'index']);
Use Context Values as a Contexual Attribute
Martin Bean contributed a #[Context()]
contextual attribute you can use to inject a context value. The pull request example demonstrates reusing a seeded value defined in the context:
use App\Models\User;use Illuminate\Database\Seeder;use Illuminate\Support\Facades\Context; class UserSeeder extends Seeder{ public function run(): void { $user = User::factory()->create(); // Store context data for subsequent seeders... Context::add('user', $user); }} //Reuse the `$user` context in the ChannelSeederuse App\Models\Channel;use App\Models\User;use Illuminate\Container\Attributes\Context;use Illuminate\Database\Seeder; class ChannelSeeder extends Seeder{ public function run( // Retrieve context data with added type-hinting... #[Context('user')] User $user, ): void { $channel = Channel::factory()->create(); $channel->users()->attach($user); }}
See Pull Request #55760 for implementation details.
Release notes
You can see the complete list of new features and updates below and the diff between 12.14.0 and 12.15.0 on GitHub. The following release notes are directly from the changelog:
v12.15.0
- [12.x] Add locale-aware number parsing methods to Number class by @informagenie in https://github.com/laravel/framework/pull/55725
- [12.x] Add a default option when retrieving an enum from data by @elbojoloco in https://github.com/laravel/framework/pull/55735
- Revert "[12.x] Update "Number::fileSize" to use correct prefix and add prefix param" by @ziadoz in https://github.com/laravel/framework/pull/55741
- [12.x] Remove apc by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/55745
- [12.x] Add param type for
assertJsonStructure
&assertExactJsonStructure
methods by @milwad-dev in https://github.com/laravel/framework/pull/55743 - [12.x] Fix type casting for environment variables in config files by @adamwhp in https://github.com/laravel/framework/pull/55737
- [12.x] Preserve "previous" model state by @crynobone in https://github.com/laravel/framework/pull/55729
- [12.x] Passthru
getCountForPagination
on an Eloquent\Builder by @cosmastech in https://github.com/laravel/framework/pull/55752 - [12.x] Add
assertClientError
method toTestResponse
by @shane-zeng in https://github.com/laravel/framework/pull/55750 - Install Broadcasting Command Fix for Livewire Starter Kit by @joshcirre in https://github.com/laravel/framework/pull/55774
- Clarify units for benchmark value for IDE accessibility by @mike-healy in https://github.com/laravel/framework/pull/55781
- Improved PHPDoc Return Types for Eloquent's Original Attribute Methods by @clementbirkle in https://github.com/laravel/framework/pull/55779
- [12.x] Prevent
preventsLazyLoading
exception when usingautomaticallyEagerLoadRelationships
by @devajmeireles in https://github.com/laravel/framework/pull/55771 - [12.x] Add
hash
string helper by @istiak-tridip in https://github.com/laravel/framework/pull/55767 - [12.x] Update
assertSessionMissing()
signature to matchassertSessionHas()
by @nexxai in https://github.com/laravel/framework/pull/55763 - Fix: php artisan db command if no password by @mr-chetan in https://github.com/laravel/framework/pull/55761
- [12.x] Types: InteractsWithPivotTable::sync by @liamduckett in https://github.com/laravel/framework/pull/55762
- [12.x] feat: Add
current_page_url
to Paginator by @mariomka in https://github.com/laravel/framework/pull/55789 - Correct return type in PhpDoc for command fail method by @Muetze42 in https://github.com/laravel/framework/pull/55783
- [12.x] Add
assertRedirectToAction
method to test redirection to controller actions by @xurshudyan in https://github.com/laravel/framework/pull/55788 - [12.x] Add Context contextual attribute by @martinbean in https://github.com/laravel/framework/pull/55760