LARAVEL Tutorial


Laravel 6 Routing Tutorial


In laravel, all HTTP or https requests are allowed with the help of routes. Because laravel routing allows to associated all requests from controllers. In this laravel routing tutorial, you will learn about the routing in Laravel.

Basic Routing Laravel

Basic routing in laravel, all requests are allowed with the help of routes. You can go to the application routes folder and define routes here. For your web application you can define application related routes in routes/web.php file and routes/api.php, here define api related routes 

routes/web.php, Here is the basic routing example for demonstration:

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

Routing with Controller Functions

Routing with Controller Functions in laravel, all requests are allowed with the help of routes. You can pass a controller method into the route. When you request from the browser or hit the route on browser. This method of the defined controller will be perform the it's action.

routes/web.php, Here is the routing with controller example for demonstration:

Route::get('/privacy-policy', 'ContentController@privacy-policy');

Routing With Parameters in Laravel

Laravel framework allow to pass parameters in routes. So You can easily pass the parameters in routes. 

routes/web.php, Here is the routing with parameters example for demonstration:

Route::get('/page/{num}', function ($num) {

    echo "Your are on page ". $num;
});

Naming Routes in Laravel

Laravel framework has very special and most important features of naming in routes. It allows to the routes to creating URLs to redirect. In other words, we can say that the naming route is the way of providing a nickname to the route in laravel web application.

routes/web.php, Here is the basic naming routes example for demonstration:

Route::post('/submit', 'ContactFormController@submitForm')->name('contact.submit');

Laravel Group Route

In laravel group routing allow to group specific or each routes with prefix, middlewares, properties etc.

routes/web.php, Here is the Laravel Group Route example for demonstration:

Route::group(['prefix' => 'admin', 'as' => 'admin.'], function () {
    Route::get('/', 'AuthController@index')->name('index');
    Route::get('/login', 'AuthController@create')->name('index');
    Route::post('/login' 'AuthController@store')->name('postLogin');
});

Namespaces in Laravel Route Groups

Laravel routes groups also allow using namespace with routes.

routes/web.php, Here is the Laravel Namespaces in Laravel Route Groups example for demonstration:

Route::group(['namespace' => 'Admin'])