Home >>Laravel Tutorial >Laravel Views
Views in web development is the structure to be displayed on web browser.
It contains all HTML code which is used to display the content of the website i.e. front-end.
Laravel views are seperated from the controller and the models of the MVC structure of laravel.
The location of views is inside resources folder.
[project_folder]/resourse/views
<html> <body> <h1>This is About Page of <?php echo $name?></h1> </body> </html>
Route::get('/about', function() { return view('About',['name'=>'PHPTPOINT']); });Here, view() is a method which has two arguments. One is the name of file containing the view, and other with an array passed to pass a variable to the view file.
http://127.0.0.1/aboutyou'll be displayed as the view you've created.
So far we returned a view which is simple just for the knowledge of view how it shows up. Let's now create a view which works with the view() method in controller class.
public function show() { return view('about'); }
<html> <body> <h1>About Us Page using Controller</h1> </body> </html> </html>
Route::get('/show','ViewController@show');Here, you can see the '/show' is the url which on access runs 'ViewController' and then the 'show' method is then run inside the ViewController
http://127.0.0.1/show
There can be views inside the sub-directory in resourse/views directory.
<html> <body> <h1>Details View inside Admin Folder</h1> </body> </html>
public function show() { return view('admin.details'); }
Route::get('/details', 'ShowController@show');
http://127.0.0.1/details
In Laravel view exists or not is determined by using view facades. exists() method returns true if view exists.
So in the above example we can check this thing by adding following conditions inside ShowController.php to check view existance.
use Illuminate\Support\Facades\View; public function show(){ if(View::exists('admin.details')) { echo "the View of admin.details exist"; } else { echo "View does not exist"; } }
Here, View::exists('admin.details') determines that admin.details exist or not.