Laravel - Blade Templates - Including Subviews

While you're free to use the @include directive, Blade components provide similar functionality and offer several benefits over the @include directive such as data and attribute binding.

Blade's @include directive allows you to include a Blade view from within another view. All variables that are available to the parent view will be made available to the included view:

    
    
@include('shared.errors')

Even though the included view will inherit all data available in the parent view, you may also pass an array of additional data that should be made available to the included view:

    
    @include('view.name', ['status' => 'complete'])
	

If you attempt to @include a view which does not exist, Laravel will throw an error. If you would like to include a view that may or may not be present, you should use the @includeIf directive:

    
    @includeIf('view.name', ['status' => 'complete'])
	

If you would like to @include a view if a given boolean expression evaluates to true or false, you may use the @includeWhen and @includeUnless directives:

    
    @includeWhen($boolean, 'view.name', ['status' => 'complete'])
    
    @includeUnless($boolean, 'view.name', ['status' => 'complete'])
	

To include the first view that exists from a given array of views, you may use the includeFirst directive:

    
    @includeFirst(['custom.admin', 'admin'], ['status' => 'complete'])
	
You should avoid using the __DIR__ and __FILE__ constants in your Blade views, since they will refer to the location of the cached, compiled view.