Press ESC to close

Laravel View

  • Jun 20, 2024
  • 1 minute read
  • 96 Views

What is view.?

In MVC, "V" stands for Views. It keeps the app logic and presentation logic separate.

Views are stored in resources/views directory.

While building application  it may be required to pass data to the views.

Please take a look at the example below to gain a better understanding of views.

Step 1 − Copy the following code and save it at resources/views/test.php

<html>
   <body>
      <h1>Hello, coder wel come to codelearning.</h1>
   </body>
</html>

Step 2 − Add the following line in app/Http/routes.php file to set the route for the above view.

Route::get('/test', function() {
   return view('test');
});

Or you can use the code below to set the view.

Route::view('/test','test');

Step 3 − Check out this URL to see the view.

http://your-project-url/test

Or

http://localhost:8000/test

Thanks 😊 

Leave a comment

Your email address will not be published. Required fields are marked *