Support the ongoing development of Laravel.io →
posted 6 years ago

i have set of controller all of them are working , except controller called RestaurantsController , however the old routes in it are working when i add to it new route are not recognized and i got error :

(2/2) NotFoundHttpException No query results for model [App\Restaurant] hello

in Handler.php line 131 at Handler->prepareException(object(ModelNotFoundException)) in Handler.php line 109 at Handler->render(object(Request), object(ModelNotFoundException)) in Handler.php line 47 at Handler->render(object(Request), object(ModelNotFoundException))

however the routes and controller is defined correctly :

Route::prefix('restaurants')->group(function (){

Route::get('/', 'RestaurantsController@index')->name('Restaurants.list');
Route::post('/', 'RestaurantsController@store');
Route::get('/create', 'RestaurantsController@create');
Route::get('/{restaurant}', 'RestaurantsController@showprofile')->name('restaurant.showprofile');
Route::put('/{restaurant}', 'RestaurantsController@update');
Route::delete('/{restaurant}', 'RestaurantsController@destroy');
Route::get('/{restaurant}/edit', 'RestaurantsController@edit');
Route::get('/hello', 'RestaurantsController@hello');

// Route::post('/registerrestaurant_store', 'RestaurantsController@register_restaurant_store');

});

Last updated 3 years ago.
0

you have to put your /hello above your /{restaurant}. Laravel is trying to resolve the {variable} instead of the /hello so its looking for a Restaurant model of /hello from that {} above

Route::get('/', 'RestaurantsController@index')->name('Restaurants.list');
Route::post('/', 'RestaurantsController@store');
Route::get('/create', 'RestaurantsController@create');
Route::get('/hello', 'RestaurantsController@hello'); //<--put this here so it is resolved before the following line
Route::get('/{restaurant}', 'RestaurantsController@showprofile')->name('restaurant.showprofile');
Route::put('/{restaurant}', 'RestaurantsController@update');
Route::delete('/{restaurant}', 'RestaurantsController@destroy');
Route::get('/{restaurant}/edit', 'RestaurantsController@edit');

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Zaid alphacoder001 Joined 25 Nov 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.