# Locale-aware Number Parsing
12.15 新增 Number class 新增 method,支援 parse with different locale
<?php
use Illuminate\Support\Number;
Number::parse($string);
Number::parseInt($string);
Number::parseFloat($string);
// Pass locale
Number::parseFloat(string: $string, locale: 'de');
// It is also possible to pass the type to the parse method
Number::parse(
string: $string,
type: NumberFormatter::TYPE_INT64,
locale: 'de',
);
# Default Option When Retrieving an Enum
12.15,request()->enum() 支援 default value
<?php
// 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
12.15,TestResponse 新增 assertClientError()
<?php
// Before
$this->assertTrue($response->isClientError());
// After
$response->assertClientError();
# String hash Helper Method
12.15 Stringable 新增 hash() method
<?php
// 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-');
$appId = str('secret-unique-key')
->hash('xxh3')
->take(10)
->prepend('app-');
// app-0fb8aac18c
# Add current_page_url to the Paginator
12.15 新增 current_page_url to Paginator
<?php
$paginator->toArray()['current_page_url'];
# Assert Redirect to Action
12.15 新增 assertRedirectToAction() action
<?php
$this->get('redirect-to-index')
->assertRedirectToAction([TestActionController::class, 'index']);
# Use Context Values as a Contexual Attribute
12.15 支援以 attribute 的方式來取得 context attribute
<?php
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 ChannelSeeder
use 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);
}
}