Laravel Blade Include File If Exists Example

By Hardik Savani | March 5, 2021 | Category : Laravel


Today, i would like to show you laravel blade include file if exists. this example will help you include if file exists laravel blade. it's simple example of how to include file if exists in laravel blade. it's simple example of laravel blade include if exists.

if you need to include file if exists in laravel 6, laravel 7 and laravel 8 then this example will help you.

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. it will only include when it's exists.

let's see bellow simple example:


<!DOCTYPE html>






@includeIf('products.alert', ['type' => 'success'])




<div class="alert alert-{{$type}}">

This is Alert.


Controller File Code:


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AjaxController extends Controller



* Create a new controller instance.


* @return void


public function index()


return view('ajaxRequest');



I hope it can help you...

Tags : Laravel

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: