-2

in laravel 9 , what is the difference between

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

and

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

?

Lab Devices
  • 43
  • 1
  • 6
  • 1
    https://laravel.com/docs/10.x/routing Check the documentation. `Route::get()` defines a single route associated with a `GET` Request, while `Route::resource()` creates a bunch of Routes associated with `GET`, `POST`, `DELETE`, etc. for a single Model (Blog): https://laravel.com/docs/10.x/controllers#resource-controllers (Docs for 10.x, but should still be applicable to 9.x) – Tim Lewis Feb 27 '23 at 19:22

1 Answers1

1

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)