I have tried to create a route with GET methode and doesnt work !!!
the route i would like to see on browser bar
http://*******:8000/products/categories/index
My controller
public function index(Request $request)
{
$categories = Category::where('parent_id', null)->orderby('name', 'asc')->get();
return view('products.categories.allcategories', compact('categories'));
}
My View folder for catategories under products
views
products
categories
My Route file
Route::get('products/categories', [CategoryController::class, 'index'])->name('index');
when type php artisan route:list i have my route listed but when i try to get the category page it show 404 not found :
http://********:8000/products/categories
if i change the route to this and controller index function to list then it works
Route::get('products/categories/list', [CategoryController::class, 'index'])->name('index');
any idea where i made error !
3
Answers
you should try
php artisan route:cache
i use that code after add new route always and it’s work
You’re going to the wrong url you need to go to
The index method does not relate to the URL but the action.
Your
products/{product}
route is conflicting with theproducts/categories
one; it’s trying to find a product matchingcategories
.This can typically be resolved by reordering the two routes in the routes file, or adding a
->where('^[0-9]+$')
constraint to theproducts/{product}
route if{product}
is supposed to be numeric.