Reputation: 1367
Is there a way to define aditional parameter for index action with which I can control my request to database.
Example
Route::resource('photo', 'PhotoController');
URL: www.somesite.com/photo/newyork
So I can get all photos from DB where i have city field value equal to newyork. (or something that will be defined by parameter in URL) (I know that this will trigger show action, but is there a way ? )
EDIT
I want to accomplish reduced set returned from database by using Eloquent ORM and Resource Controllers. e.g. All picture names that have city field in database equal to newyork.
Upvotes: 2
Views: 1412
Reputation: 7050
The best way to accomplish this is to not add another URL segment, but to use a URL/GET parameter. For example www.somesite.com/photo?city=newyork
. Then you can write a validation rule that city
is required. This is the most flexible system which will allow you to add additional parameters, as needed, without changing routes in the future. Examples:
www.somesite.com/photo?city=newyork&order=name_asc
www.somesite.com/photo?city=newyork&type=donut_shop
www.somesite.com/photo?city=newyork&order=name_asc&type=donut_shop
If you're interested more in Resource controllers and/or building API's you should check out this book. You'll be able to pick up some good tips.
Upvotes: 3