Laravel 7.4 发布
Laravel 团队昨天发布了 v7.4.0 版本,其中包含相当多的新特性,例如自定义的模型转换器接口、 When 高阶集合代理,以及从查询构建器中清除现有 order 的功能。 高阶的 When 集合代理Loris Leiva 贡献了使用高阶代理的能力,它的方法是? // PR 中的相关代码 $collection->when($condition,function ($collection) use ($item) { $collection->push($item); }); // 现在重构为 $collection->when($condition)->push($item);
此 PR 使您能够链接其他高阶代理方法: // 以前 $collection->when($condition,function ($collection) { $collection->map->parseIntoSomething(); }); // 现在重构为 $collection->when($condition)->map->parseIntoSomething();
对于 Artisan 命令行增加 expectsChoice () 进行选择Adrian Nürnberger 提供了一个控制台测试方法,用于在命令行中询问你的选择。 就像下面这样: $name = $this->choice('What is your name?',['Taylor','Dayle'],$defaultIndex);
之前你只能断言此问题的回复,不能测试选择: $this->artisan('question') ->expectsQuestion('What is your name?','Taylor') ->assertExitCode(0);
在 Laravel7.4,你可以给出选项,像下面这样做: $this->artisan('question') ->expectsChoice('What is your name?','Taylor','Dayle']) ->assertExitCode(0);
你还可以在第四个参数传入一个 boolean 类型的值,用来保证选择顺序 $this->artisan('question') ->expectsChoice('What is your name?',true) ->assertExitCode(0);
为 Blade 的 @props 标签添加默认值@props 拥有了自定义默认值的能力 <!-- 以前的版本: --> @props(['type','message']) @php $type = $type ?? 'info' @endphp <!-- Laravel >=7.4 --> @props(['type' => 'info','message'])
Castable 接口Brent Roose 贡献了一个?Castable?接口,允许? // 以前 class ModelX extends Model { protected $casts = [ 'data' => CastToDTO::class . ':' . MyDTO::class,]; } // 现在 class ModelY extends Model { protected $casts = [ 'data' => MyDTO::class,]; } // 基础类 use IlluminateContractsDatabaseEloquentCastable; class MyDTO implements Castable { public static function castUsing() { return CastToDTO::class . ':' . static::class; } }
从查询构建器中删除?
|