Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 method to check is view exists?

Tags:

laravel

view

Is there any method to check if view exists?

Like PHP file_exists, but using internal laravel method for convenience

i want to code like this:

if(__ifViewExist__($view)){     return view($view)->render(); } return "Page tidak ditemukan"; 
like image 970
Nuha Dzikri Avatar asked May 28 '16 14:05

Nuha Dzikri


People also ask

How do you check user is exist or not in Laravel?

$result = User::where("email", $email)->exists(); The above clause will give true if record exists and false if record doesn't exists. So always try to use where() for record existence and not find() to avoid NULL error.

How do I return a view in Laravel?

Views may also be returned using the View facade: use Illuminate\Support\Facades\View; return View::make('greeting', ['name' => 'James']); As you can see, the first argument passed to the view helper corresponds to the name of the view file in the resources/views directory.

How do I load a view in Laravel controller?

Loading a view in the controller is easy. You just need to add `view('viewname')` method while returning from the controller method. `view()` is a global helper in Laravel. In this method, you just need to pass the name of the view.

What is view Laravel?

What are the views? Views contain the html code required by your application, and it is a method in Laravel that separates the controller logic and domain logic from the presentation logic. Views are located in the resources folder, and its path is resources/views.


1 Answers

Yes, an exists() method is available.

if(view()->exists($view)){     return view($view)->render(); } return "Page tidak ditemukan"; 
like image 96
IllegalPigeon Avatar answered Sep 29 '22 03:09

IllegalPigeon