₹2,000.00 ₹300.00
  • 15 students
  • 12 lessons
  • 0 quizzes
  • 10 week duration


Routing in Laravel-1

Route definitions in Laravel are given in the routes directory in Laravel.

Routes are written into the web.php file.



The contents of the web.php file now.


| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!

Route::get('/', function () {
return view('welcome');


Route::get(‘/’, function () {
return view(‘welcome’);

shows the default page which shows the welcome view.



Let us define a new Route.


Route::get('/one', function () {
return 'one';

Route with parameters.

Route::get(‘two/{id}’, function ($id) {
return ‘two ‘.$id;

This is a fixed parameter called $id.

Try calling it.




Next, we shall have optional parameters. In these cases you give a default value.

Route::get('three/{id?}', function ($id=0) {
return 'three '.$id;


Regular Expressions in routing.

Route::get(‘id/{name?}’, function ($name=”noname”) {
return “name” . $name;
->where(‘name’, ‘[A-Za-z]+’);

Route::get(‘id/{id?}’, function ($id=”000″) {
return “phone” . $id;
->where(‘id’, ‘[0-9]+’);

All alphabetic ids will go to the name route and numerical ones to the phone group.




One thought on “Routing in Laravel-1

Leave a Reply

Your email address will not be published. Required fields are marked *