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');
});
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');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community