编程

Laravel 9.22 更新:重新设计了 Artisan serve 命令等

849 2022-08-01 04:59:13

Laravel 团队发布了 9.22 版本,更新包括:重新设计了 Artisan serve 命令,文件验证规则生成器,等。

流式文件验证规则

Luke Downing 贡献了一个文件验证规则,提供了类似于 Password 验证规则那样的流式接口:

// 之前
$request->validate([
  'file' => ['required', 'file', 'mimes:mp3,wav,aac', 'max:12287'],
  'image' => ['required', 'file', 'image', 'min:2048', 'max:12287', Rule::dimensions()->maxWidth(1000)->maxHeight(500)],
]);
 
// 之后
$request->validate([
  'file' => ['required', File::types(['mp3', 'wav', 'aac'])->smallerThan(12 * 1024)],
  'image' => ['required', File::image()->atLeast(2 * 1024)->smallerThan(12 * 1024)->dimensions(Rule::dimensions()->maxWidth(1000)->maxHeight(500))],
]);

改善 Artisan serve 命令

紧接着全新的 Artisan 外观,Nuno Maduro 对 artisan serve 命令也进行了改进:

Check out Pull Request #43375 for more screenshots and details about these changes.

在MailMessage中附上文件数组

Delowar Hossain Tim MacDonald 合作为邮件信息提供了 attachMany() 方法:

$mailable->attachMany([
    '/forge.svg',
    '/vapor.svg' => ['as' => 'Vapor Logo.svg', 'mime' => 'text/css'],
    new class() implements Attachable
    {
        public function toMailAttachment()
        {
            return Attachment::fromPath('/foo.jpg')->as('bar')->withMime('image/png');
        }
    },
]);

注意,你也可以多次调用 attach() 实现。

 

添加条件性语句到邮件信息中

El Shino  贡献了条件性添加语句到邮件消息的能力:

// With a conditional
$message->line('Your order has been canceled');
if ($this->amount > 0) {
    $message->line("The refunded amount is {$this->amount}");
}
 
// Using lineIf
$message->line('Your order has been canceled')
        ->lineIf($this->amount > 0, "The refunded amount is {$this->amount}");

文件i同提供多种哈希算法

Douglas Medeiros 贡献了文件系统对多种哈希算法的支持。现在,你可以在第二个参数(可选)中指定哈希算法:

File::hash($path)
// 196b0f14eba66e10fba74dbf9e99c22f => default md5
 
File::hash($path, 'sha256')
// 19c451aedfb24c338a9a2a5c31d553ed77e7cdefc655035f390176ac24066051

v9.22.1

Added

  • Added unique locking to broadcast events (#43416)

Fixed

  • Fixes Artisan serve command on Windows (#43437)

v9.22.0

Added

  • Added ability to attach an array of files in MailMessage (#43080)
  • Added conditional lines to MailMessage (#43387)
  • Add support for multiple hash algorithms to Illuminate/Filesystem/Filesystem::hash() (#43407)

Fixed

  • Fixes for model:show when attribute default is an enum (#43370)
  • Fixed DynamoDB locks with 0 seconds duration (#43365)
  • Fixed overriding global locale (#43426)

Changed

  • Round milliseconds in console output runtime (#43400)
  • Improves serve Artisan command (#43375)