laravel 团队昨天发布了 v7.4.0 版本,其中包含相当多的新特性,例如自定义的模型转换器接口、 when 高阶集合代理,以及从查询构建器中清除现有 order 的功能。
loris leiva 贡献了使用高阶代理的能力,它的方法是collection::when()
// pr 中的相关代码$collection->when($condition, function ($collection) u ($item) { $collection->push($item);});// 现在重构为$collection->when($condition)->push($item);
此 pr 使您能够共青团工作总结链接其他高阶代理方法:
// 以前$collection->when($condition, function ($collection) { $collection->map->parintosomething();});// 现在重构为$collection->when($condition)->map->parintosomething();
adrian nürnberger 提供了一个控制台测试方法,用于在命令行中询问你的选择。
就像下面这样:
$name = $this->choice('what is线路板设计 your name?', ['taylor', 'dayle'], $defaultindex);
之前你只能断言此问题的回复,不能测试选择:
$this->artisan('question') ->expectsquestion('what is your name?', 'taylor') ->asrtexitcode(0);
在 laravel7.4,你可以给出选项,像下面这样做:
$this->artisan('question') ->expectschoice('what is your name?', 'tay湖心亭看雪教案lor', ['taylor', 'dayle']) ->asrtexitcode(0);
你还可以在第四个参数传入一个 boolean 类型的值,用来保证选择顺序
$this->artisan('question') ->expectschoice('what is your name?', 'taylor', ['taylor', 'dayle'], true) ->asrtexitcode(0);
@props 拥有了自定义默认值的能科目4安全文明驾驶力
<!-- 以前的版本: -->@props(['type', 'message'])@php $type = $type ?? 'info'@endphp<!-- laravel >=7.4 -->@props(['type' => 'info', 'message'])
brent roo 贡献了一个castable接口,允许castable
类型指定其基础类:
// 以前class modelx extends model{ protected $casts = [ 'data' => casttodto::class . ':' . mydto::class, ];}// 现在class modely extends model{ protected $casts = [ 'data' => mydto::class, ];}// 基础类u illuminate\contracts\databa\eloquent\castable;class mydto implements castable{ public static function castusing() { return casttodto::class . ':' . static::class; }}
order
jonathan reinink 为查询构建器贡献了一个reorder()
方法,用于重置其orderby()
:
$query = db::table('urs')->orderby('name');$unorderedurs = $query->reorder()->get();
重新排序允许您在雄辩的关系中定义默认顺序,并能够在需要时取消:.
class account extends model{ public function urs() { return $this->hasmany(ur::class)->orderby('name'); }}// 删除名称 orderby 和 order by email$account->urs()->reorder()->orderby('email');// 同样可以写成:$account->urs()->reorder('email');
您可以在下面看到新功能和更新的完整列表以及在 github 上看到 [7.3.0 和 7.4.0] 之间的区别(https://github.com/laravel/framework/compa…)
更多学习内容请访问:
八重樱:腾讯t3-t4标准精品php架构师教程目录大全,只要你看完保证薪资上升一个台阶(持续更新)
本文发布于:2023-04-08 11:14:09,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/9a5f639f1092000eb7ad3cfe51209c44.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Laravel 7.4 发布.doc
本文 PDF 下载地址:Laravel 7.4 发布.pdf
留言与评论(共有 0 条评论) |