Reverse routing trong Laravel là gì?
Reverse routing trong Laravel là gì?
Reverse routing là sinh URL từ tên route (và tham số) thay vì viết cứng đường dẫn. Khi đổi URL trong file route, mọi nơi dùng tên route tự cập nhật theo.
// routes/web.php
Route::get('/san-pham/{product:slug}', [ProductController::class, 'show'])->name('products.show');
// Sinh URL
route('products.show', $product); // https://site.com/san-pham/ao-thun
route('products.show', ['product' => 'ao-thun', 'ref' => 'home']); // tham số thừa thành query string
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.