Reputation: 12222
I am new in Laravel
.
routes/api.php I have written this function
Route::group(['namespace' => "Catalogue"],function(){
Route::resource('product','Product');
});
I have created a resource controller:
app/Controllers/Catalogue/Product.php
This is my index method:
public function index()
{
$pdo = DB::select('select count(*) from offers');
return $pdo;
}
I am trying to get the result from index method from url:
http://localhost:8000/api/Catalogue/product
However, this results in 404 not found
.
Note: There is no issue in this part of url http://localhost:8000/api
Upvotes: 1
Views: 1185
Reputation: 11906
Based on your route the link generated is http://localhost:8000/api/product
If you need the link to be http://localhost:8000/api/Catalogue/product , then add the prefix to the group.
Route::group(['prefix' => 'Catalogue', 'namespace' => 'Catalogue'], function() {
Route::resource('product', 'Product');
});
The namespace
only sets the default namespace for the controller. The prefix
sets the route prefix for all the routes in the group.
Upvotes: 1
Reputation: 28
You are hitting the wrong uri.
Check http://localhost:8000/api/product
The namespace in the group route means you are assigning a namespace to a group of controllers. As you can see here https://laravel.com/docs/5.4/routing#route-group-namespaces. It has nothing to do with the routes.
Here you can see the other routes when you make them in the controller. https://laravel.com/docs/5.4/controllers#controllers-and-namespaces
Upvotes: 1