ItSolutionStuff.com

Laravel Blade Check if View Exists or Not Example

By Hardik Savani β€’ April 16, 2024
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, laravel 10 and laravel 11 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: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Laravel Global Variable for All Views Example

Read Now β†’
β˜…

How to Pass Data from Controller to View in Laravel?

Read Now β†’
β˜…

Laravel React JS File Upload Example Tutorial

Read Now β†’
β˜…

Laravel 9 Ajax File Upload with Progress Bar Tutorial

Read Now β†’
β˜…

Laravel Eloquent whereRaw Condition Example

Read Now β†’
β˜…

Laravel Copy File from One Folder to Another Example

Read Now β†’
β˜…

How to Create Blade File in Laravel using CMD?

Read Now β†’
β˜…

How to Get Current URL in Laravel?

Read Now β†’
β˜…

Laravel Generate PDF from HTML View File and Download Example

Read Now β†’
β˜…

How to Pass Data to All Views using Composer Share in Laravel?

Read Now β†’
β˜…

How to Change View Mode in Bootstrap Datepicker Like yyyy-mm?

Read Now β†’
β˜…

How to use Inject View in Laravel?

Read Now β†’
β˜…

Laravel Ajax Render View With Data Example

Read Now β†’
β˜…

Laravel Create JSON File & Download From Text Example

Read Now β†’