0
votes

Am trying to add a route in my api.php in laravel, whereas all other api are working fine but newly added api is not working returning 404.

Route::get('products','Api\ProductsController@index');
Route::get('products/trending','Api\ProductsController@trendingProducts');

Products return data but when searched for trending it returns 404. Tried clearing route cache and checking in route list. The route exist in routelist. Even the function in controller also existl.

Controller Code :

public function trendingProducts(){
    echo "i";        
}

Confused by the unexpected behaviour. Any help will be gratefull. Thank you in advance.

1
Does the controllermethod perform an abort() or has a findOrFail() in it? Have you cleared your routes cache? php artisan optimize:clearQirel
Maybe show what's inside your controllersjewishmoses
Show whats inside your controllers so we can help you moreHarout
hi @HaroutFMD added controller code just returning i form there.Santosh Upadhyay
Dint know how it happen and why but places that url all above and it started working any idea why so @haroutSantosh Upadhyay

1 Answers

0
votes

You have to use like this

href="{{url('')}}/api/products/trending"