Laravel 9 Route Controller Group Improvements Example

Hello Artisan,

In this example, I will show you controller route group improvements in laravel 9. From the version of Laravel 9, we can now use the controller method to define the common controller for all of the routes within the group. See the below example:

Previously we could define a route like that:

Route::get('webcam', WebcamController::index)->name('webcam.capture');
Route::post('webcam', WebcamController::store);

 

Now we can do that same job like below: 

Route::controller(WebcamController::class)->group(function () {
    Route::get('webcam', 'index')->name('webcam.capture');
    Route::post('webcam', 'store');
});

 

We can make a group with the controller name. No need to call the same controller again. 

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js
ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT