php - laravel NotFoundHttpException appears though I have the function -
php - laravel NotFoundHttpException appears though I have the function -
i have code
<li> <a href="{{ url::to('restaurants/admins/25') }}"> <i class="fa fa-location-arrow"></i> profile </a> </li> and in routes, have this:
route::resource('restaurants', 'restaurantscontroller'); but got error:
symfony \ component \ httpkernel \ exception \ notfoundhttpexception could help please?
tl;dr
i suggest utilize url restaurants/25/admins instead of restaurants/admins/25 entities ordered big small, i.e. restaurants -> 1 restaurant -> restaurant's admin. so, reply i'm going use:
<a href="{{ url::to('restaurants/25/admins') }}"> then in route can do:
route::get('restaurants/{id}/admins'), 'restaurantscontroller@admins'); route::resource('restaurants', 'restaurantscontroller'); and in controller code, do:
class restaurantscontroller { // code index(), show(), etc... public function admins($id) { // whatever want laravel /restaurants/{id}/admins } } long answer:
let me explain bit on resource controller does. in laravel, when do:
route::resource('restaurants', 'restaurantscontroller'); it more or less helper automatically expands these:
route::get ('restaurants', 'restaurantscontroller@index'); route::get ('restaurants/{id}', 'restaurantscontroller@show'); route::get ('restaurants/create', 'restaurantscontroller@create'); // there few more generated. see http://laravel.com/docs/controllers#resource-controllers as know, first route displaying restaurants. sec route displaying specific restaurant. 3rd displaying form add together restaurant.
one note laravel simply generates routes don't need write many routes on , over. write in controller's methods (a.k.a. functions) depends totally on you. create /restaurants show form adding restaurants, , /restaurants/create show restaurants list. destroys purpose of resource controllers because it's suppose create write code easier , shorter, while still beingness understandable!
so if conform laravel does. one-line route:
route::resource('restaurants', 'restaurantscontroller'); you url reserved displaying restaurants (/restaurants), url displaying specific restaurant (/restaurants/{id}), , url form add together new restaurant (/restaurants/create). note: there 7 routes i'm mentioning 3 here brevity.
if understand correctly, trying add together feature. want page shows list admins restaurant. not fit 3 urls have yet, decided create 1 e.g. restaurants/admins/25.
my first recommendation that, when structuring url, seek arrange biggest entity smallest. original restaurants/admins/25 translates to:
restaurants > admins of restaurant > 1 restaurant
if you, go this:
restaurants > 1 restaurant > admins of restaurant
so instead of restaurants/admins/25 url be:
<a href="{{ url::to('restaurants/25/admins') }}"> can sense difference? have urls much more comprehensible:
restaurants <-- show restaurants restaurants/25 <-- show restaurant #25 restaurants/25/admins <-- show admins in restaurant #25 restaurants/create <-- show form create new restaurant now route file needs line back upwards admins our custom action:
route::get('restaurants/{id}/admins'), 'restaurantscontroller@admins'); route::resource('restaurants', 'restaurantscontroller'); and in controller code, do:
class restaurantscontroller { // code index(), show(), etc... public function admins($id) { // whatever want laravel /restaurants/{id}/admins } } from here on, can add together /restaurants/25/info, /restaurants/25/photos, etc. same way above.
php laravel laravel-4 blade
Comments
Post a Comment