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
        于 8年前 加精
            
                 
           JokerLinly 的个人博客
 JokerLinly 的个人博客
         
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
                     
                     
             
           
           关于 LearnKu
                关于 LearnKu
               
                     
                     
                     粤公网安备 44030502004330号
 粤公网安备 44030502004330号 
 
推荐文章: