Beginner LevelLaravel
What are Resource Controllers and how do they map to RESTful actions?
❓ Interview Prompt: Explain Resource Controllers (php artisan make:controller --resource), Route::resource, and 7 standard RESTful actions.
Resource controllers assign standard CRUD routes to a controller with a single line of code ('Route::resource("photos", PhotoController::class)').
7 Standard Actions:
1
index(): GET /photos (List records)
2
create(): GET /photos/create (Render creation form)
3
store(): POST /photos (Save new record)
4
show(): GET /photos/{photo} (Display single record)
5
edit(): GET /photos/{photo}/edit (Render edit form)
6
update(): PUT/PATCH /photos/{photo} (Update record)
7
destroy(): DELETE /photos/{photo} (Delete record)
Code Implementation Example
php
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersProductController;
// Maps all 7 RESTful routes in 1 line
Route::resource('products', ProductController::class);💡Mapping RESTful CRUD routes using Route::resource.
🎯 Interview Key Takeaway
Resource controllers standardize CRUD controller method names and simplify RESTful routing.
#Controllers#Resource Controllers#RESTful#Beginner
Back to all Laravel Questions→