laravel5.2.15
Laracon is almost upon us. Unfortunately for me, I will not be able to attend. Guess, I'll have to wait for a couple of months to watch it on Youtube. That aside, this year's Laracon will be the stage for unveiling Laravel 5.3. Before the official release, we will look at a rundown of the new features coming to Laravel.
拉腊Kong(Laracon )快要降临了。 不幸的是,我将无法参加。 猜猜,我将不得不等待几个月才能在YouTube上观看它。 除此之外,今年的Laracon将成为发布Laravel 5.3的舞台。 在正式发布之前,我们将了解Laravel即将推出的新功能。
Since Laravel uses semver to version its releases, we know that this release is a minor release. Meaning we should expect minor features and some patches. Let's get started.
由于Laravel使用semver对其发行版进行版本控制,因此我们知道此发行版是次要发行版。 这意味着我们应该期待一些次要功能和一些补丁。 让我们开始吧。
刀锋的foreach $ loop ( Blade's foreach $loop )
This new release introduces a $loop
variable inside a foreach
loop. This variable provides a couple of properties that can help us easy manage indexes, increments in loops etc. Now in Laravel 5.3, we can do stuff like.
这个新版本在foreach
循环中引入了$loop
变量。 这个变量提供了几个属性,可以帮助我们轻松管理索引,循环增量等。现在在Laravel 5.3中,我们可以做类似的事情。
<ul>
@foreach ($countries as $country)
@if ($loop->count)
@if ($loop->first)
<li class="list-item list-item--header">{{ $country->name }}</li>
@elseif ($loop->last)
<li class="list-item list-item--footer">{{ $country->name }}</li>
@else
<li class="list-item">{{ $country->name }}</li>
@endif
@endif
@endforeach
</ul>
多种迁移路径 ( Multiple Migration Paths )
If you have ever installed a Laravel package that needs a database migration, it involves you copying some migrations into the migration folder, but with Laravel 5.3 — a package can define its migration path, and when you run php artisan migrate
all migrations will run without you having to clutter your migration directory.
如果您曾经安装过需要数据库迁移的Laravel软件包,则需要将一些迁移复制到迁移文件夹中,但是使用Laravel 5.3-软件包可以定义其迁移路径,并且当您运行php artisan migrate
所有迁移都将在不进行迁移的情况下进行您必须使迁移目录混乱。
To let Laravel know about another migration directory, simply do.
要让Laravel知道另一个迁移目录,只需执行。
$this->loadMigrationsFrom('path/to/migrations/folder');
查询生成器返回一个集合 ( Query Builder Returns a Collection )
The query builder used to return an array. If we wanted to perform a large array of operations on the returned dataset, we would have to loop through the array. But collections makes that really simple for us to handle. So because of that reason, the query builder just like the ORM now returns a collection of objects. There is a pull request on the topic.
查询生成器用于返回数组。 如果我们想对返回的数据集执行大量操作,则必须遍历该数组。 但是集合使我们处理起来非常简单。 因此,由于这个原因,查询生成器就像ORM一样现在返回对象的集合。 有一个关于该主题的请求请求 。
Now we can do stuff like this.
现在我们可以做这样的事情。
$result = DB::table('posts')->get();
if ($result->first()) { }
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }
This was not available before. Now, we can do cool operations like pluck
, filter
etc.
以前没有此功能。 现在,我们可以执行一些很酷的操作,例如pluck
, filter
等。
分步迁移回滚 ( Migration Rollback in Steps )
Instead of rolling back our entire migrations, we can now rollback in steps. With the new step
flag added to artisan
. So, now we can do this.
现在,我们可以分步回滚,而不必回滚整个迁移。 随着新的step
标志添加到artisan
。 因此,现在我们可以做到这一点。
php artisan migrate:rollback --step=1
自定义简单分页的能力 ( Ability to Customize Simple Pagination )
Laravel is bringing back the ability to customize simple navigation with views. You can also still use the pagination templates if you want, but this is still a nice feature to have. We can do stuff like this.
Laravel恢复了使用视图自定义简单导航的功能。 如果需要,您仍然可以使用分页模板,但这仍然是一个不错的功能。 我们可以做这样的事情。
<ul class="pagination">
@if ($paginator->onFirstPage())
<li class="disabled"><span>«</span></li>
@else
<li>
<a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a>
</li>
@endif
</ul>
Check out the official announcement on twitter.
在Twitter上查看官方公告 。
Laravel回声 ( Laravel Echo )
Echo is meant to be an improvement over the current event broadcasting system. It seamlessly integrates with pusher's JavaScript library.
回声是对当前事件广播系统的改进。 它与pusher的 JavaScript库无缝集成。
Taylor Otwell has made a video to better explain Echo. Echo also has an npm package that makes using sockets on the frontend easier.
泰勒·奥特威尔(Taylor Otwell)制作了一段录像,以更好地解释回声。 Echo还有一个npm软件包,可以使在前端使用套接字更加容易。
杂项和结论 ( Misc and Conclusion )
Other features included with version 5.3 are:
5.3版附带的其他功能包括:
- Eloquent Collections are cleanly serialized and re-pulled by queued jobs. 雄辩的收藏被干净地序列化 ,并由排队的作业重新拉出。
- Queue console output changed to show the actual class names. 队列控制台输出已更改为显示实际的类名 。
- firstOrCreate: now allows additional parameters. firstOrCreate:现在允许其他参数 。
In conclusion, maybe in a major release — support for MongoDB. What would you like to see in future versions of Laravel, let us know down in the comments?
总之,也许在一个主要版本中-对MongoDB的支持。 您想在Laravel的未来版本中看到什么,请在评论中告知我们?
翻译自: https://scotch.io/tutorials/laravel-5-3-new-features-and-updates
laravel5.2.15