문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top