includeWhen(Laravel 5.4 的新变化系列)
为这个功能提 PR 的 James Brooks 想用它来优化模板中的 if 语句,旨在让模板引擎看上去更优雅。
来个经典例子:
@if(Auth::user())
@include('nav.user')
@endif
用 includeWhen
就可以简化成:
@includeWhen(Auth::user(), 'nav.user')
换个例子:
@if ($user->ownsPost($post))
@include('posts.edit-controls', ['post' => $post])
@endif
可以简化成这样:
@includeWhen($user->ownsPost($post), 'posts.edit-controls', ['post' => $post])
更多资讯可前往 Laravel China 资讯站 查看
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由 Summer
于 7年前 加精
这个可以的哦
不错哦!!!支持!!
@overtrue @xhh110 :satisfied:
简便多了