编程

Laravel 9.41 发布

963 2022-11-29 02:33:35

Laravel 发布了 9.41版本。新特性包括软删除模型的验证规则,另外的 rule builder 的快捷方法,when missing 请求方法,等等。

"Only trashed" 数据库验证规则

Michael Nabil 为数据库的 exists 和 unique 规则贡献了 onlyTrashed() 条件。这一特性可以验证数据库的软删除数据列:

Validator::make(
    [
        'name' => 'Michael Nabil',
    ],
    [
        'name' => [
            'required',
            Rule::exists('users')->where('id', $this->id)->onlyTrashed(),
            Rule::unique('users')->where('id', $this->id)->onlyTrashed(),  // Or
        ],
    ]
);

规则构造器(Rule builder)快捷方法

Michael Nabil 为image、Enum、dimension 和 unique 贡献了一些规则构造器:

// Before
$request->validate([
    'password' => Password::default(),
    'image' => File::default(),
    'status' => new Enum(StatusEnum::class),
    'name' => Rule::requiredIf(function () {
        return true;
    })
]);
 
// Now you can also do:
$request->validate([
    'password' => Password::default(),
    'image' => Rule::file()->default(),
    'status' => Rule::enum(StatusEnum::class),
    'name' => Rule::requiredIf(function () {
        return true;
    })
]);

当输入值缺失时的请求回调函数

@phh 贡献了 whenMissing() 方法,可以在输入缺失时调用回调函数:

$request->whenMissing('name', function ($value) use (&$name) {
    $name = 'Taylor';
});

该方法也能在key没有缺失时,接收一个默认的 callable。

在 Vite facade 上自定义 manifest 文件

Nagesh TiwariTim MacDonald 贡献了自定义 Vite manifest 文件的能力。API 工作方式如下:

// Service provider
use Illuminate\Support\Facades\Vite;
 
Vite::useManifestFilename('custom-manifest.json');

现在,在模板中,下面的的例子将会使用自定义的 manifest 文件:

{{-- Uses the custom manifest filename --}}
 
@vite(['resources/js/app.js'])
 
{{-- Inline example --}}
{{ Vite::useManifestFilename('custom-manifest.json')->withEntryPoints(['resources/js/app.js']) }}

v9.41.0

Added

  • Added Illuminate/Validation/Rules/DatabaseRule::onlyTrashed() (#44989)
  • Add some class rules in class Rule (#44998)
  • Added Illuminate/View/ComponentAttributeBag::missing() (#45016)
  • Added Illuminate/Http/Concerns/InteractsWithInput::whenMissing() (#45019)
  • Add isolation levels to SQL Server Connector (#45023)
  • Fix php artisan serve with PHP_CLI_SERVER_WORKERS > 1 (#45041)
  • Add ability to prune cancelled job batches (#45034)
  • Adding option for custom manifest filename on Vite Facade (#45007)

Fixed

  • Fix deprecation warning when comparing a password against a NULL database password (#44986, 206e465)
  • Outlook web dark mode email layout fix (#45024)

Changed

  • Improves queue:work command output (#44971)
  • Optimize Collection::containsStrict (#44970)
  • Make name required in Illuminate/Testing/TestResponse::assertRedirectToRoute() (98a0301)
  • Strip key, secret and token from root config options on aws clients (#44979)
  • Allow customised implementation of the SendQueuedMailable job (#45040)
  • Validate uuid before route binding query (#44945)