Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Resource Controllers

Build RESTful APIs quickly with resource controllers.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Create Controller
  2. Register Routes
  3. Available Methods
  4. Partial Resource

Resource controllers:

Create Controller

php artisan make:controller PostController --resource

Register Routes

php
Route::resource('posts', PostController::class);

Available Methods

index()   - GET /posts
create()  - GET /posts/create
store()   - POST /posts
show()    - GET /posts/{post}
edit()    - GET /posts/{post}/edit
update()  - PUT /posts/{post}
destroy() - DELETE /posts/{post}

Partial Resource

php
Route::resource('posts', PostController::class)
    ->only(['index', 'show']);

Route::resource('posts', PostController::class)
    ->except(['destroy']);
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read