How you can use the routes in Laravel 4.2

Hi guys. In this tutorial I will explain to you how you can use the routes in Laravel Framework version 4.2. You can find, create and edit existing routes from app/routes.php.

So, lets go to create the first route in Laravel.

Route::get('/', function()
{
return 'Hello World';
});

This route will display Hello World in the first page of your Laravel project.

Route::post('foo/bar', function()
{
return 'Hello World';
});

This route also will display Hello World if you will go to http://localhost/laravel/test/public/foo/bar

Route::get('foo', array('https', function()
{
return 'Must be over HTTPS';
}));

This route will force to be served over Https.

Also you can create routes with parameters:

Route::get('user/{id}', function($id)
{
return 'User '.$id;
});

When you will go to http://localhost/laravel/test/public/user/100

You will see User 100

If you want to call a new page from view with your new route, use this code:

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

This route will display the content of hello.php view file.

Video tutorial:









Leave a Comment