Mastering on Routing in Laravel

Laravel Logo of tisuchi

Routing is important for every website as well as application. Today I am going tell about the mechanism of routing in web engineering. Basically routing will decide where will be your destination? In laravel, there is a special class for routing. Lets open app>routes.php files.

Route::get('/', function()
        return View::make('hello');

In this file, we are grabbing Route class from core Route class (vendor > laravel > framework > src > Illuminate > Routing > Route.php).  Inside the core Route class, there is a static get() function and we are by default using this get() function.  Inside this function, we laravel created a another function as a parameter.

       return View::make('hello');

Now, going inside this function, you will see there is a return option. But you have to understand how this function will work. Well, considering this function, I am going to comments the return option and put something new as follows-

       //return View::make('hello');
       return 'foo';

and run your laravel project then you can see the ‘foo’ text instead of default laravel welcome page.  Hope, it is clear to everyone that, how this function works. Now lets go to see how View::make() part will work.

Routing in Laravel of tisuchi

return View::make('hello');

The above line return a View options for visitor in this url and then create a view page for that. Inside the bracket, they mentioned which file will be shown here.  Look the following code-

return View::make('app/view/hello.php');  
return View::make('app/view/hello.blade.php');

This is the original things that happened in route file but laravel minimized the full url to short from like return View::make(‘hello’). Now you haven’t to write all the things.  Beside this, blade is a template engine for PHP and laravel is using this template engine.


Well, now lets go for something more techniques for controlling your URL. Sometimes, you have to create url like In previous example, we see the simple url handling option like Now lets take a look how can we do that-

Route::get('about/me', function()
        return View::make('hello');

Finish? yes. Lets browse your laravel project and you can see the HTTPException for not founding the proper directory because we have changed the main url.  Now try this (http://………. /about/me). Perhaps you can see the laravel by default welcome page. Perfect, this is the simple things that how can you handle the url in laravel project.


Hope, this tutorial will help you to understand the routing of laravel project. Do comments if you have any questions. 

Thank you.



Leave a Reply

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

You are commenting using your 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