How to Check If a Blade File Exists in Laravel?

Hello artisan,

In this laravel check if blade file exists tutorial, I will show you how we can check inside a laravel controller and also inside blade file whether a blade view file exists or not in laravel. If you don't know how to write condition of laravel check if blade file exists then this example is for you. Laravel provides View::exists() or view()->exists() method to check whether a blade view file exists or not in laravel.

We can use this source code with laravel 6, laravel 7, laravel 8 and laravel 9 versions. We can use View facade or view() helper to check blade or view file exists or not in laravel. Let's see the below examples:


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
    public function index()
        if (view()->exists('home'))
            return view('home');


Check inside blade file:

    {{-- Blade File is Exists --}}
    {{-- Blade File is not Exists --}}


Read also: Different Ways of Passing Data From Controller to View in Laravel


Hope it can help you.


Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js