Controller xử lý logic của request, thường ứng với một resource (User, Product): nhận request, làm việc với Model, rồi trả về View hay JSON. php artisan make:controller ProductController --resource sinh sẵn bộ method CRUD — index() (danh sách), show($id) (một bản ghi), create() (form tạo), store() (lưu form), edit() (form sửa), update() (lưu sửa đổi), destroy() (xoá).
php
public function store(Request $request)
{
$product = Product::create($request->validated());
return redirect()->route('products.show', $product);
}Lưu ý: luôn dùng $request->validated() chứ đừng dùng $request->all() — all() mở đường cho lỗ hổng mass assignment.