Laravel 9.8版本发布

2023-06-01 00:00:00 laravel 版本 发布

最近laravel9的小版本更新的有点快啊,我们来看看前天发布的laravel9.8版本。

Laravel 团队发布了 9.8 版本,其中包含从 Eloquent 模型访问默认表单数据、每个异常类型的自定义日志级别、在其他路径中发现匿名组件等等:

> Laravel 9.8.0 现已推出,其中包含几个很酷的新功能!

一是提升“老”帮手的生活质量。 您现在可以将模型作为第二个“默认”参数传递。
该函数将根据第一个参数假定属性名称。

pic.twitter.com/1Mee6Tv20j

-- Taylor Otwell (@taylorotwell) 2022 年 4 月 12 日


“旧”表单助手接受模型

Andrew Arscott 对 old() 帮助器进行了更新,它允许将模型作为第二个默认参数:

<input type="text" name="name" value="{{ old('name', $user->name) }}">
 
{{-- --}}
<input type="text" name="name" value="{{ old('name', $user) }}">



在异常处理中允许自定义日志级别

Tom Witkowski 贡献了在异常处理程序中为报告的异常自定义日志级别的能力:

use PDOException;
use Psr\Log\LogLevel;
 
/**
 * A list of exception types with their corresponding custom log levels.
 *
 * @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
 */
protected $levels = [
    PDOException::class => LogLevel::CRITICAL
];

有关实施详细信息,请参阅 Pull Request #41925。

https://github.com/laravel/framework/pull/41925


在其他路径中发现匿名刀片组件

Ralph J. Smit 贡献了在其他路径中发现匿名 Blade 组件的能力:

public function boot()
{
    Blade::anonymousComponentNamespace('flights.bookings', 'flights');
}

下面是一个匿名组件使用的例子:

<x-flights::panel :flight="$flight" />


设置工厂方法

Ralph J. Smit 贡献了一个模型工厂 set() 方法来设置单个模型属性:

// Before
EloquentModel::factory()
    ->create(['name' => 'foo']);
 
// After
EloquentModel::factory()
    ->set('name', 'foo')
    ->create();
 
// Before
EloquentModel::factory()
    ->someMethod()
    ->create(['country' => 'NL']);
 
// After
EloquentModel::factory()
    ->someMethod()
    ->set('country', 'NL')
    ->create();


发行说明

您可以在下面查看新功能和更新的完整列表以及 GitHub 上 9.7.0 和 9.8.0 之间的差异。

https://github.com/laravel/framework/compare/v9.7.0...v9.8.0


转:

https://laravel-news.com/laravel-9-8-0

相关文章