in laravel , what is the differace between Route::resource and Route::get?

303 Views Asked by At

in laravel 9 , what is the difference between

Route::resource('/blog',[PostController::class);

and

Route::get('/blog',[PostController::class,'index']);

?

1

There are 1 best solutions below

0
Saint Spirit On BEST ANSWER

Resource route will generate all CRUD routes:

Verb          Path                       Action  Route Name
GET           /blog                      index   blog  index
GET           /blog/create               create  blog  create
POST          /blog                      store   blog  store
GET           /blog/{post}               show    blog  show
GET           /blog/{post}/edit          edit    blog  edit
PUT|PATCH     /blog/{post}               update  blog  update
DELETE        /blog/{post}               destroy blog  destroy

Second variant will generate only one GET route (first in the list)