In this article i am going to define at five Laravel Blade directives you can use to simplify your templates, and learn about some convenient directives that make solving specific problems on each.

  1. Check if the user is authenticated
    if(auth()->user())
    // The user is authenticated.
    endif
  2. Check if the user is a guest
    if(auth()->guest())
    // The user is not authenticated.
    endif
  3. Include the first view if it exists or includes the second if it doesn’t
    if(view()->exists(‘first-view-name’))
    include(‘first-view-name’)
    else
    include(‘second-view-name’)
    endif
  4. Include a view based on a condition
    if($post->hasComments())
    include(‘posts.comments’)
    endif
  5. Include a view if it exists
    if(view()->exists(‘view-name’))
    include(‘view-name’)
    endif
    If you going to use simple way-
    @includeIf(‘view-name’)
News Reporter
IT Software and web development, Core PHP, JavaScript, JQuery, HTML, CSS, CakePHP, Angularjs, Codeigniter etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: