0

I need to make a url with undetermined number of parameters. So I want to make search.

For example:

test.com/recipes/{category?}/{country?}/{ingredients?}/{eingredients?}

test.com/breakfast/france/ingredients/45/147/180/eingredients/2/79/205
test.com/france/eingredients/2/79/205
test.com/breakfast/ingredients/45/147/180
test.com/breakfast

ingredients and eingredients are arrays.

ingredients - included in the recipe (ids) eingredients - excluded from the recipe (ids)

I have an idea:

Route::get('/recipes/{category?}/{country?}/{ingredients?}/{eingredients?}', 'RecipeController@index')
->where(['ingredients' => '^ingredients/[0-9\/]+$', 'eingredients' => '^eingredients/[0-9\/]+$']);

but it does not work:

test.com/france/eingredients/2/79/205

I get page 404...

How i can make it?

P.S: I just started learning laravel.

  • You can't make undetermined number of parameters. And check the order. Your orders doesn't match with your routes. Even you are using wrong address. – itachi Nov 29 '15 at 17:46

2 Answers2

0

You can use GET parameters to feet your needs test.com/search?country=france&category=breakfast.... If you want url to look like /country/***/ then you can make them, and in .htaccess file rewrite them to get parameters. And to be sure about order, in search url add some info, for example: test.com/county/france/category/breakfast/****

EchoGlobal.tech
  • 694
  • 4
  • 8
0

Duplicate of: https://stackoverflow.com/a/21526071/2420002.

 Route::get('{pageLink}/{otherLinks?}', 'SiteController@getPage');

//controller 
class SiteController extends BaseController {

    public function getPage($pageLink, $otherLinks = null)
    {
        if($otherLinks) 
        {
            $otherLinks = explode('/', $otherLinks);
            //do stuff 
        }
    }

}
Community
  • 1
  • 1
Tim van Uum
  • 1,873
  • 1
  • 17
  • 36
  • It is a good idea. But then, too, will be divided IDS. ingredients/45/147/180/eingredients/2/79/205 [0] = ingredients [1] = 45 [2] = 147 [3] = 180 [4] = eingredients [5] = ... – Billy Milligan Nov 30 '15 at 07:37