'How to use one Route for a controller to hit all actions in Laravel 8

I switched to Laravel 8 from CakePhp and I would like to know if it's possible to use only one route for all the actions in a controller. I found "Implicit Controllers" for Laravel 4.2 but it's not working on version 8.



Solution 1:[1]

Is not possible to use one route for all actions. However what you can do is use the resource function so that laravel will automatically generate the routes using the CRUD model. You can find the documentation in: https://laravel.com/docs/9.x/controllers#resource-controllers. So, you could declare the route as:

 Route::resource('photos', PhotoController::class);

And that will generate:

            Route::get('/posts', 'PostController@index');
            Route::get('/posts', 'PostController@create');
            Route::post('/posts', 'PostController@store');
            Route::get('/posts/{postId}', 'PostController@show');
            Route::get('/posts/{postId}/edit', 'PostController@edit');
            Route::put('/posts/{postId}', 'PostController@update');
            Route::delete('/posts/{postId}', 'PostController@destroy');

Solution 2:[2]

You can use just this Route:

Route::resource('crud','App\Http\Controllers\CrudsController');

for these function :

index/create/store/show/edit/update/destroy

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 a bcd