Laravel 9 released controller grouping in route. Now we can create a route controller group in our route. In Laravel 8, there is no option like that. But in Laravel 9, we can make a controller grouping route in Laravel 9.

This is the Laravel 8 version of route:

routes/web.php

<?php 

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\System\ProtocolController;

Route::get('protocols',[ProtocolController::class,'index'])->name('protocol');
Route::get('protocol/create',[ProtocolController::class,'create'])->name('protocol.create');

 

This is the Laravel 9 version of route:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\OrderController;
 
Route::controller(OrderController::class)->group(function () {
    Route::get('/orders/{id}', 'show');
    Route::post('/orders', 'store');
});

 

That means If a group of routes utilizes the same controller then we can use the controller method to define the common controller for all of the routes within the group.

 

Read also: Laravel 9 Get Current Route Name In Blade Example

 

Hope it can help you.

Category : #laravel

Tags : #laravel , #laravel routing