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

Laravel 10.14版本发布

Laravel  /  管理员 发布于 2年前   411

本周, Laravel团队发布了v10.14版本,新增了can验证规则,定义自定义Gate拒绝响应,全局HTTP客户端中间件,HTTP客户端便利方法,以及更多:

 >最近合并到Laravel, Rule::can验证规则, 允许你在表单输入上授权一个能力!
  这允许你将一些授权逻辑从控制器中移到表单请求中 -- 并显示一个验证错误,而不是自己处理它。 
  pic.twitter.com/UvC52Q8WZa
 
 - Steve Bauman (@ste_bau) 6月22日, 2023

Rule::can()验证规则

Steve Bauman贡献了Rule::can()验证规则,它提供了一种为给定表单字段授权能力的方法。

下面是Pull Request #47371中给出的例子。

给出以下PostPolicy:

// Given the following policy
class PostPolicy
{
    // ...
 
    public function updateAuthor(User $user, Post $post)
    {
        return $user->isAdmin();
    }
}

我们可以验证用户是否有能力更新作者:

use App\Models\Post;
 
class PostRequest extends FormRequest
{
    public function rules()
    {
        return [
            'author' => Rule::can('update-author', Post::class, $this->route('post')),
            'title' => '...',
            'body' => '...',
        ];
    }
}


为Gate@inspect()中的拒绝设定一个自定义响应

Luke Kuzmish 贡献了在 Gate 的 inspect() 方法失败时设置返回响应的能力。

例如,当与can()中间件一起使用时:

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Gate::setDenialResponse(Response::denyAsNotFound());
    }
}


全局HTTP中间件

Tim MacDonald贡献了定义全局HTTP客户端中间件的能力,它被应用于HTTP客户端的每个请求:

// In a service provider...
 
use Illuminate\Support\Facades\Http;
 
// Global request middleware
Http::globalRequestMiddleware(
    fn ($request) => $request->withHeader('User-Agent', 'Laravel Framework/1.0')
);
 
// Global response middleware
Http::globalResponseMiddleware(
    fn ($response) => $response->withHeader('X-Finished-At', now()->toDateTimeString())
);
 
// Complete global middleware that wraps both request and response
Http::globalMiddleware(function ($handler) {
    return function ($request, $options) use ($handler) {
        $startedAt = now();
 
        return $handler($request, $options)
            ->then(fn ($response) => $response->withHeader(
                'X-Duration', $startedAt->diffInMilliseconds(now())
            ));
    };
});

你也可以定义一次性的middlware--查看Pull Request #47525中的所有细节,看看有什么可能!


为PendingRequest增加一个withHeader()方法

Ralph J. Smit贡献了一个withHeader方法,用于在使用HTTP客户端时设置一个单一的头:

// Using an array
Http::baseUrl(config('services.active-campaign.endpoint') . '/api/3')
    ->withHeaders([
        'Api-Token' => config('services.active-campaign.token')
    ])
    ->acceptJson();
 
 
// Setting a single header using `withHeader()`
Http::baseUrl(config('services.active-campaign.endpoint') . '/api/3')
    ->withHeader('Api-Token', config('services.active-campaign.token'))
    ->acceptJson();


在HTTP客户端添加withQueryParameters便利方法

Matthieu Napoli贡献了一个withQueryParameters()方法,作为定义查询参数的便利方法,这些参数应该总是在HTTP请求中被定义:

// Using `withOptions()`
Http::baseUrl('https://api.convertkit.com/v3/')
    ->withOptions([
        'query' => [
            'api_secret' => config('services.convertkit.api_secret'),
        ],
    ])
    ->acceptJson();
 
// Using the new `withQueryParameters()` method
Http::baseUrl('https://api.convertkit.com/v3/')
    ->withQueryParameters([
        'api_secret' => config('services.convertkit.api_secret'),
    ])
    ->acceptJson();


发布说明

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

下面的发行说明直接来自更新日志:

https://github.com/laravel/framework/compare/v10.13.0...v10.14.0
https://github.com/laravel/framework/blob/fff5b0bf6eefccbedfa88405b97435f9eb4e3452/CHANGELOG.md#v10140---2023-06-27


v10.14.0

[10.x] 添加RedirectResponse中withCookies方法的测试
by @milwad-dev in https://github.com/laravel/framework/pull/47383

[10.x] 增加新的错误信息 "SSL: Handshake timed out "处理到PDO Dete...
by @yehorherasymchuk in https://github.com/laravel/framework/pull/47392

[10.x] 增加新的错误信息以检测丢失的连接
由 @mfn 在https://github.com/laravel/framework/pull/47398

[10.x] 更新中间件的phpdoc except方法
by @milwad-dev 在 https://github.com/laravel/framework/pull/47408

[10.x] 修复$passwordTimeoutSeconds的不一致的类型提示
by @devfrey 在 https://github.com/laravel/framework/pull/47414

改变FileStore.php中路径方法的可见性
作者:@foremtehan 在 https://github.com/laravel/framework/pull/47413

[10.x] 修正buildException方法的返回类型
by @milwad-dev 在 https://github.com/laravel/framework/pull/47422

[10.x] 允许NotificationSent的序列化
由 @cosmastech 在https://github.com/laravel/framework/pull/47375

[10.x] PredisConnector和PhpRedisConnector中不正确的注释
由 @hungthai1401 在 https://github.com/laravel/framework/pull/47438 发表

[10.x] 可以在Gate@inspect()中设置自定义的Response进行拒绝,
由@cosmastech在https://github.com/laravel/framework/pull/47436。

[10.x] 删除addSingletonUpdate中不必要的参数
作者:@milwad-dev 在 https://github.com/laravel/framework/pull/47446

[10.x] 修正prefixedResource & prefixedResource的返回类型
by @milwad-dev in https://github.com/laravel/framework/pull/47445

[10.x] 增加Factory::getNamespace()
作者:@tylernathanreed 在 https://github.com/laravel/framework/pull/47463

[10.x] 为ConditionallyLoadsAttributes特性添加whenAggregated方法
by @akr4m in https://github.com/laravel/framework/pull/47417

[10.x] 添加PendingRequest withHeader()方法
by @ralphjsmit 在 https://github.com/laravel/framework/pull/47474

[10.x] 修正$exceptTables,允许使用表名数组,
作者:@cwilby 在https://github.com/laravel/framework/pull/47477

[10.x] 修正HasManyThrough关系中的eachById,
由@cristiancalara在https://github.com/laravel/framework/pull/47479。

[10.x] 允许禁用自定义类铸造者的对象缓存
由 @CalebDW 在 https://github.com/laravel/framework/pull/47423 发表

[10.x] "Can "验证规则
由 @stevebauman 在https://github.com/laravel/framework/pull/47371

[10.x] 重构(Parser.php): 删除多余的 "else "语句
作者:@saMahmoudzadeh 在 https://github.com/laravel/framework/pull/47483

[10.x] 在 ValidationServiceProvider 中的 provides() 中添加 UncompromisedVerifier::class,
由 @xurshudyan 在 https://github.com/laravel/framework/pull/47500 发表

[10.x] Reindex appends attributes
by @hungthai1401 in https://github.com/laravel/framework/pull/47519

[10.x] 修复ListenerMakeCommand的弃用
由 @dammy001 在 https://github.com/laravel/framework/pull/47517 发表

[10.x] 增加HandlesPotentiallyTranslatedString特性
by @xurshudyan 在https://github.com/laravel/framework/pull/47488

[10.x] 更新[JsonResponse]:使用匹配表达式而不是if-elseif-else
by @saMahmoudzadeh 在 https://github.com/laravel/framework/pull/47524

[10.x] 在HTTP客户端中添加withQueryParameters
由 @mnapoli 在 https://github.com/laravel/framework/pull/47297 发表

[10.x] 允许组件属性名称中的%符号
由 @JayBizzle 在 https://github.com/laravel/framework/pull/47533 发表

[10.x] 修复Http客户端池的返回类型
由 @srdante 在 https://github.com/laravel/framework/pull/47530 中提供

[10.x] 在resolveSynchronousFake中使用匹配表达式
by @osbre in https://github.com/laravel/framework/pull/47540

[10.x] 在compileHaving中使用匹配表达式
by @osbre in https://github.com/laravel/framework/pull/47548

[10.x] 在getArrayableItems中使用匹配表达式
by @osbre in https://github.com/laravel/framework/pull/47549

[10.x] 修复SessionGuard的返回类型
by @PerryvanderMeer 在 https://github.com/laravel/framework/pull/47553

[10.x] 修复DatabaseQueue中的返回类型
by @PerryvanderMeer 在https://github.com/laravel/framework/pull/47552

[10.x] 修复DumpCommand中的返回类型
by @PerryvanderMeer 在https://github.com/laravel/framework/pull/47556

[10.x] 修复MigrateMakeCommand的返回类型
by @PerryvanderMeer in https://github.com/laravel/framework/pull/47557

[10.x] 添加缺失的回报给工厂,
由 @PerryvanderMeer 在https://github.com/laravel/framework/pull/47559

[10.x] 更新Eloquent模型中的文档
由 @alirezasalehizadeh 在https://github.com/laravel/framework/pull/47562

[10.x] 修正返回类型
由 @PerryvanderMeer 在 https://github.com/laravel/framework/pull/47561 发表

[10.x] 修复PHPDoc的抛出类型
作者:@fernandokbs 在 https://github.com/laravel/framework/pull/47566

[10.x] 为ComponentAttributeBag添加hasAny函数,允许has函数中的多个键
由@indykoning在https://github.com/laravel/framework/pull/47569。

[10.x] 确保捕获的时间是在配置的时区
由 @timacdonald 在 https://github.com/laravel/framework/pull/47567 发表

[10.x] 增加只报告已记录的异常的方法
by @joelharkes 在 https://github.com/laravel/framework/pull/47554

[10.x] 为Http客户端添加全局中间件
by @timacdonald in https://github.com/laravel/framework/pull/47525

这个版本时隔半个月,终于发布了,看起来东西有点多。


转:

https://laravel-news.com/laravel-10-14-0

  • 上一条:
    在php中实现排除某个时间段后在计算俩个时间的时间差代码示例
    下一条:
    在laravel框架中用ChatGPT生成代码的扩展包推荐:laravel-synth
  • 昵称:

    邮箱:

    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个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(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个评论)
    • 近期评论
    • 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交流群

    侯体宗的博客