Basic routing in laravel

Rakesh Sharma      No Comments  

Basic get and post routing in laravel 5 :-

Routing in laravel 5 defined in the app/Http/routes.php file. Another good features of Laravel is it’s routing.
Laravel routes consist of a URI and a Closure callback. we will see how we can manage or apply routing in laravel. We need to set routes both for post and get method in laravel. so need to learn and define routing in laravel site.
In this blog we will see basic routing in laravel 5 for static pages and Route parameter. So we need to make route for each url like,

Static pages (Basic GET Routing) :-

Make default home page resources/views/home.blade.php

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

Access :-

contact page resources/views/contact.blade.php

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

Access :-

Now i have a contact form and i need to post contact form values to my ContactController method send() then i need to make a post routing.
For this i need to set one more route in app/Http//routes.php for post data. below routes will work to post your contact info on this controller method.

Basic POST Routing :-

Route::post('contact/send', 'ContactController@send');

Form post action :- (contact/send)

404 Errors (Error Routing):-

It’s easy to handle errors like 404, 500 with routing. we need to define routes and done.
error page resources/views/error.blade.php

    return Response::view('error', array(), 404);



Now you can easily configure routes in laravel 5 for your site and access all pages and post data and also can handle errors in laravel.
You can get more information about Routing in laravel 5