laravellaravel-controllerlaravel-resource

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


in laravel 9 , what is the difference between

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

and

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

?


Solution

  • 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)