侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Laravel 11.4版本发布

Laravel  /  管理员 发布于 1年前   359

本周,Laravel团队发布了v11.4,具有可逆形式的Prompts、新的Exceptions外观、

Collection::mapInto()方法中的Enum支持等。


介绍例外立面

努诺·马杜罗(Nuno Maduro)贡献了“例外”的门面:

Exceptions facade提供了一种一致的方法来测试Laravel应用程序中的异常。

以下是Exceptions facade提供的方法列表:

assert报告
assertReportedCount
assertNotReported
assertNothing报告
throwOnReport
throwFirstReported


以下是pull请求描述中的一个示例,

说明Exceptions::fake()方法和assertReported()方法:

use Illuminate\Support\Facades\Exceptions;
 
test('example', function () {
    Exceptions::fake();
 
    $this->post('/generate-report', [
        'throw' => 'true',
    ])->assertStatus(503); // Service Unavailable
 
    Exceptions::assertReported(ServiceUnavailableException::class);
 
    // or
    Exceptions::assertReported(function (ServiceUnavailableException $exception) {
        return $exception->getMessage() === 'Service is currently unavailable';
    });
});

有关更多详细信息,请阅读我们的Laravel测试中断言异常的文章。


Livewire样式指令

@devajmeireles提供了使用布尔型指令的能力,而不需要任何定义的值:

{{-- Before  --}}
 
<x-fetch wire:poll />
 
{{-- Generates this HTML --}}
 
<div ... wire:poll="wire:poll" />
 
{{-- After  --}}
<x-fetch wire:poll />
 
<div ... wire:poll />



提示中的可逆形式

Luke Downing提供了表单提示,这是一组分组提示,供用户完成。

表单可以返回到以前的提示并进行更改,而无需取消命令并重新开始:

use function Laravel\Prompts\form;
 
$responses = form()
    ->text('What is your name?', required: true)
    ->password('What is your password?', validate: ['password' => 'min:8'])
    ->confirm('Do you accept the terms?')
    ->submit();


以下是使用先前响应中的值的示例:

$responses = form()
    ->text('What is your name?', name: 'name')
    ->add(fn () => select('What is your favourite language?', ['PHP', 'JS']), name: 'language')
    ->add(fn ($responses) => note("Your name is {$responses['name']} and your language is {$responses['language']}"))
    ->submit();

有关实现的详细信息,请参阅laravel/prompts项目中的Pull Request#118。

该功能已在Prompts文档中进行了说明。


在mapInto集合方法上添加对枚举的支持

Luke Downing对Collection::mapInto()方法上的枚举提供了支持,

该方法允许您从值的数组中构建枚举:

public function store(Request $request)
{
    $request->validate([
        'features' => ['array'],
        'features.*' => [new Enum(Feature::class)],
    ]);
 
    $features = $request
        ->collect('features')
        ->mapInto(Feature::class);
 
    if ($features->contains(Feature::DarkMode)) {
        // ...
    }
}



afterQuery()钩子

Günther Debrauer在运行查询后贡献了一个afterQuery()钩子来运行代码:

$query->afterQuery(function ($models) {
    // Make changes to the queried models ...
});


以下是pull请求描述中的一个用例示例:

// Before
 
public function scopeWithIsFavoriteOf($query, ?User $user = null) : void
{
    if ($user === null) {
        return $query;
    }
 
    $query->addSelect([
        // 'is_favorite' => some query ...
    ]);
}
 
$products = Product::withIsFavoriteOf(auth()->user())->get();
 
if (auth()->user() === null) {
    $products->each->setAttribute('is_favorite', false);
}

下面是使用afterQuery()钩子的代码:

// After
 
public function scopeWithIsFavoriteOf($query, ?User $user = null) : void
{
    if ($user === null) {
        $query->afterQuery(fn ($products) => $products->each->setAttribute('is_favorite', false));
 
        return;
    }
 
    $query->addSelect([
        // 'is_favorite' => some query ...
    ]);
}
 
Product::withIsFavoriteOf(auth()->user())->get();


发布说明

你可以在下面看到新功能和更新的完整列表,以及GitHub上11.3.0和11.4.0之间的差异。

以下发行说明直接来自更改日志:

https://github.com/laravel/framework/compare/v11.3.0...v11.4.0
https://github.com/laravel/framework/blob/b90eebc5b418bd1776d1521ebd56b7eb529d919f/CHANGELOG.md#v1140---2024-04-16


v11.4.0

[11.x]Apc缓存-通过@sserpentblade在中删除长期消失的Apc_*功能https://github.com/laravel/framework/pull/51010

[11.x]允许@devajmeireles在中使用Livewire Wire布尔样式指令https://github.com/laravel/framework/pull/51007

[11.x]在中引入@nunomaduro的Exceptions facadehttps://github.com/laravel/framework/pull/50704

[11.x]通过@gdebrauwer在中查询钩子后https://github.com/laravel/framework/pull/50587

在中通过@maddhatter修复映射到错误表的计算列https://github.com/laravel/framework/pull/51009

[11.x]@saMahmoudzadeh对字符串标题的改进测试https://github.com/laravel/framework/pull/51015

[11.x]修复@gdebrauwer在使用sql server时查询方法测试失败的问题https://github.com/laravel/framework/pull/51016

[11.x]修复:通过@sjspereira在检查存储库是否存在之前应用数据库连接https://github.com/laravel/framework/pull/51021

[10.x]修复在查询中使用orderByRaw()时的错误,然后由@axlon在中使用cursorPaginate()https://github.com/laravel/framework/pull/51023

[11.x]在中添加@timmydhooghe的RequiredIfDeclined验证规则https://github.com/laravel/framework/pull/51030

[11.x]通过@lukeraymonddowning在mapInto集合方法上添加了对枚举的支持https://github.com/laravel/framework/pull/51027

[11.x]修复@jessarcher在中使用数字键时的提示回退返回值https://github.com/laravel/framework/pull/50995

[11.x]在中通过@monurakkaya向隐式枚举路由绑定添加了对int支持的枚举的支持https://github.com/laravel/framework/pull/51029

[11.x]在中通过@sserpentblade禁用缓存库上的事件的配置https://github.com/laravel/framework/pull/51032

Revert“[11.x]displayName()设置的作业名称必须由S…由@RobertBoes在https://github.com/laravel/framework/pull/51034

家务:修复@laterlaugh在评论中的一些拼写错误https://github.com/laravel/framework/pull/51037

displayName()设置的作业名称必须由中的@SCIF按照计划执行https://github.com/laravel/framework/pull/51038

在中修复@szepeviktor的更多拼写错误https://github.com/laravel/framework/pull/51039

[11.x]在中通过@saMahmoudzadeh修复一些文档块https://github.com/laravel/framework/pull/51043

[11.x]通过@masoudtajer在Http方法上添加@throws ConnectionException标记以支持IDEhttps://github.com/laravel/framework/pull/51066

[11.x]添加提示文本区域回退测试,并在中通过@lioneaglesolutions添加断言测试https://github.com/laravel/framework/pull/51055

通过中的@timacdonald验证每个密钥的MAChttps://github.com/laravel/framework/pull/51063

[11.x]在中通过@JosephSilber将throttle方法添加到LazyCollectionhttps://github.com/laravel/framework/pull/51060

[11.x]通过@jimmypuckett在中的衰变秒或分钟,如小时和天https://github.com/laravel/framework/pull/51054

[11.x]考虑@hansnn在SyncQueue中的after_commit配置https://github.com/laravel/framework/pull/51071

[10.x]@saadsidqui在中修复数据库层https://github.com/laravel/framework/pull/49787

[11.x]修复上下文助手在中总是需要@nikspyratos的$key-value的问题https://github.com/laravel/framework/pull/51080

[11.x]修复预期使用可选多选提示的Choice断言。由@jessarcher在
https://github.com/laravel/framework/pull/51078

转:

https://laravel-news.com/laravel-11-4-0

  • 上一条:
    在laravel框架中使用Laravel Stripe Connect包实现与Stripe Connect集成示例
    下一条:
    在Laravel 11.4测试中断言异常
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • Laravel 11.14版本发布 - 新的字符串助手和ServeCommand改进(0个评论)
    • Laravel 11.12版本发布 - Artisan的`make`命令自动剪切`.php `扩展(0个评论)
    • Laravel的轻量型购物车扩展包:binafy/laravel-cart(0个评论)
    • Laravel 11.11版本发布 - 查看模型中的第三方关系:show(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-01
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客