Laravel 9 Route Group Controller Example
Today, I would like to show you Assigning a controller to a route group. This article will give you simple example of Grouping routes by controllers in Laravel. I explained simply step by step Laravel 9 route group with controller. This article goes in detailed on How To Use Controller Route Groups in Laravel.
you may use the controller method to define the common controller for all of the routes within the group. Then, when defining the routes, you only need to provide the controller method that they invoke:
Example 1:
use App\Http\Controllers\UserController;
Route::controller(UserController::class)->group(function () {
Route::get('/users/{id}', 'show');
Route::post('/users', 'store');
});
Example 2:
use App\Http\Controllers\PostController;
Route::controller(PostController::class)->group(function () {
Route::get('/posts/{id}', 'show');
Route::post('/posts', 'store');
});
It will help you...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial