How to create view in Laravel 4.2


In the MVC world, V stands for view, a view is reponsible for displaying web page when a url is requested. In this article i will show you how to create view in laravel 4.2.

A view is basically contains html, css and javascript, laravel 4.2 support two kind of page templates, the standard php template and blade template.

Blade template usually named with .blade.php extension, we are going to discuss more deeply about blade template on different article for now let's just create a simple view.

In laravel 4.2 a view is located on app/views/ folder, ok now create new folder called myproject inside app/views/ and then create a php file called welcome.php.

app/views/myproject/welcome.php
<html>
<head>
<title>This is just a page</title>
</head>
<body>
<h1>Welcome</h1>
<p>to my page</p>
</body>
</html>

And then create a route that's calling to the view we just created

routes.php
Route::get('welcome/', function()
{
 return View::make('myproject.welcome');
});

Now go ahead open that url on a web browser, it should shows like this:


Congratulation you have just created a view, note that view can also be called from a controller, i will discuss about laravel view more deeply on other article.


EmoticonEmoticon