Laravel Blade Check if View Exists or Not Example
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
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Global Variable for All Views Example
- How to Pass Data from Controller to View in Laravel?
- Laravel React JS File Upload Example Tutorial
- Laravel 9 Ajax File Upload with Progress Bar Tutorial
- Laravel Eloquent whereRaw Condition Example
- Laravel Copy File from One Folder to Another Example
- How to Create Blade File in Laravel using CMD?
- How to Get Current URL in Laravel?
- Laravel Generate PDF from HTML View File and Download Example
- How to Pass Data to All Views using Composer Share in Laravel?
- How to Change View Mode in Bootstrap Datepicker Like yyyy-mm?
- How to use Inject View in Laravel?
- Laravel Ajax Render View With Data Example
- Laravel Create JSON File & Download From Text Example