In this topic, we will learn about Views in Laravel.
The View component is used for all the UI logic of the application. It separates the application logic and the presentation logic. Views are stored in resources/views
. A simple view might look something like this:
Step 1 − Copy the following code and save it at resources/views/greetings.blade.php
<html> <body> <h1>Hello, {{ $name }}</h1> </body> </html>
Step 2 − Add the below route in appHttproutes.php file to set the route for the above view.
Route::get('/', function () {
return view('greetings', ['name' => 'Peter']);
});
The output will appear like this:
Hello, Peter
Determining If A View Exists
If you need to determine if a view exists, you may use the View facade. The exists method will return true if the view exists:
use IlluminateSupportFacadesView;
if (View::exists('categories.books')) {
//
}