Laravel Blade Include File If Exists Example

Laravel Blade Include File If Exists Example; In this tutorial you will learn How to check if a (blade) view file exists in laravel application.

laravel provide two @include directive. one is @include and another @includeIf. if you use @include then if view not exists then it throw error, but if you use @includeIf then it will not throw error.

Main Default File

Suppose you have a default file which is showing the index;


<!DOCTYPE html>
    <title>Laravel Blade Include File if exists Example -</title>
    @includeIf('products.details', ['product' => $product ])

Include File

Now create a blade file details and inlude it file file exits;


    {{ $product->name }}

Hope it help you…

Leave a Comment