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.
- Check if the user is authenticated
if(auth()->user())
// The user is authenticated.
endif - Check if the user is a guest
if(auth()->guest())
// The user is not authenticated.
endif - 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 - Include a view based on a condition
if($post->hasComments())
include(‘posts.comments’)
endif - 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’)