Laravel Blade Check if View Exists or Not Example

By Hardik Savani November 5, 2023 Category : Laravel

Hey Dev,

This article will provide some of the most important example laravel check view exists. if you want to see an example of laravel check if view exists in blade then you are in the right place. let’s discuss about laravel check if view file exists. If you have a question about how to check view exists in laravel then I will give a simple example with a solution. you will do the following things for laravel blade file exists.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 versions.

We can use View facade and helper to check blade or view file exists or not in laravel. we can check blade file exists or not in controller and blade file as well. let's see the below examples:

Example 1: Check using Helper in Controller

app/Http/Controllers/DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$title = "Welcome to ItSolutionStuff.com";

if(view()->exists('admin.demo')){

return view('admin.demo', compact('title'));

}

}

}

Example 2: Check using Facade in Controller

app/Http/Controllers/DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use View;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$title = "Welcome to ItSolutionStuff.com";

if(View::exists('admin.demo')){

return view('admin.demo', compact('title'));

}

}

}

Example 3: Check using Helper in Blade

Blade File:

@if(view()->exists('admin.demo'))

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

@else

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

@endif

Example 4: Check using Facade in Blade

Blade File:

@if(View::exists('admin.demo'))

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

@else

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

@endif

I hope it can help you...

laravel check view exists, laravel check if view exists in blade, laravel check if view file exists, how to check view exists in laravel, laravel blade file exists, laravel blade check if property exists

Tags :
Shares