Laravel View


What is view laravel?

The view is a part of the MVC pattern. The view is data that will be shown to the user in his browser and the user can interact with them. the view files are stored inside the resources/views directory.

how to create view file in laravel

Laravel doesn't have any PHP artisan command to create views files. so we have to create a manually view file and it is stored inside the resources/views directory.

resources/views/test.php

<!DOCTYPE html> 
<html> 
<head> 
    <title>This is View Files</title> 
</head> 
<body> 
    <h3>This is View Files</h3> 
</body> 
</html>

How to pass data to view in Laravel?

If you want to pass data inside the view file using controller or routes then you can do it. so you can see below example.

routes/web.php

Route::get('/test', function() {
   return view('test',[‘title’=>’This is View Files’]);
});

resources/views/test.php

<!DOCTYPE html> 
<html> 
<head> 
    <title><?php echo $title; ?></title> 
</head> 
<body> 
    <h3><?php echo $title; ?></h3> 
</body> 
</html>