Basic Routing, Controller and Views

Let us start with basic routing. If you are absolute beginner, don’t worry. Just remember, in the ‘app/Http’ folder there is a file called ‘routes.php’ where primarily the ‘request’ and ‘response’ mechanism is settled. We will discuss ‘request’ and ‘response’ architecture in detail later. But as a beginner, to start with you remember that HTTP protocol or grossly web is based on REST architecture and ‘request’ and ‘response’ cycle is the essence of the whole thing. When we say this, it is bit simplified but we will come back to this point once again.

We would like to advance our primary knowledge. We want to make some output. So forget everything and concentrate on the ‘routes.php’ file. When your application is launched, the ‘routes.php’ file looks something like this:
//code starting
<?php
Route::get('/', function () {
return view('welcome');
});
//code ended
Here 'Route' is a class that has a static method 'get' that returned a 'view' method which presents a page. When a user visits the home page he is taken to the 'welcome' page. Look at the code, there is an anonymous function also.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s