php artisan make:controller BookController –resource. What is this resource at end of artisan command? Let’s break it down in simple terms.
If you’re learning Laravel, you’ve probably seen these two commands:
php artisan make:controller BookControllerand
php artisan make:controller BookController --resourceAt first, they look similar—but they serve different purposes. Let’s break it down in simple terms.
📌 What is a Controller?
In Laravel, a controller is a file where you write logic for handling user requests.
For example:
- Show a list of books
- Add a new book
- Edit a book
- Delete a book
🧱 Option 1: Basic Controller
php artisan make:controller BookControllerThis creates an empty controller:
class BookController extends Controller
{
//
}👉 You have to:
- Write all functions yourself
- Define routes manually
✔️ Use this when:
- You need custom logic
- You are not building a standard CRUD app
⚡ Option 2: Resource Controller
php artisan make:controller BookController --resourceThis creates a controller with 7 ready-made methods:
public function index() {}
public function create() {}
public function store() {}
public function show($id) {}
public function edit($id) {}
public function update($id) {}
public function destroy($id) {}These methods follow a standard pattern called CRUD:
| Action | Method |
|---|---|
| Show all data | index |
| Show form to create | create |
| Save new data | store |
| Show one item | show |
| Show edit form | edit |
| Update data | update |
| Delete data | destroy |
🔗 The Magic of Route::resource
Instead of writing many routes, Laravel gives you a shortcut:
Route::resource('books', BookController::class);This single line creates all these routes:
| Method | URL | Controller Method |
| GET | /books | index |
| GET | /books/create | create |
| POST | /books | store |
| GET | /books/{id} | show |
| GET | /books/{id}/edit | edit |
| PUT/PATCH | /books/{id} | update |
| DELETE | /books/{id} | destroy |
🧠 Simple Example
Let’s say you are building a Book Management App:
- View all books →
index() - Add a book →
create()+store() - Edit a book →
edit()+update() - Delete a book →
destroy()
With a resource controller, everything is already structured for you 🚀
🤔 Which One Should You Use?
Use Basic Controller if:
- You need custom features
- Your app is not CRUD-based
Use Resource Controller if:
- You are building CRUD (most common case)
- You want faster development
- You want clean and organized code
💡 Beginner Tip
If you’re just starting with PHP and Laravel:
👉 Start with --resource
It helps you learn structure and saves time.
🎯 Final Thoughts
- Basic Controller = more control, more work
- Resource Controller = faster, structured, beginner-friendly
Most real-world Laravel apps use resource controllers because they follow best practices.
