Wednesday, January 19, 2022

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 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.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to 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, Angular12, Angular 13, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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