Monday, November 30, 2020
therichposts@gmail.com
LaravelPhp

How easy way to call middleware in laravel Route?

Laravel 7.2 routing with route group auth guard check with prefix

easy way to call middleware in laravel Route

Hello to all, welcome to therichpost.com. In this post, I will tell you, How easy way to call middleware in laravel Route? Laravel is one of the top php mvc framework.

Middleware in laravel use between request and response. Laravel Routes is of the best thing in laravel framework.  

Here are the ways to call middleware in laravel Route into your routes/web.php file:

//First Method
Route::post('/testpage', 'TestController@TestFunction')->middleware('ajax');

//Second if you have many routes in one Middleware
Route::middleware('ajax')->group(function () {
   Route::post('/testpage', 'TestController@TestFunction');
   Route::post('/testpage2', 'TestController@TestFunction2');
   Route::post('/testpage3', 'TestController@TestFunction3');
});

//Third if you have Multiple Middleware in one Route
Route::group(['middleware' => ['auth', 'web']], function() {
    Route::post('/testpage', 'TestController@TestFunction');
});

Route::get('/', function () {
    //
})->middleware('auth', 'web');

 There are so many code tricks in laravel and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.