简体   繁体   English

如何使用参数制作网址? Laravel 5.1

[英]How to make a url with parameters? Laravel 5.1

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) 成分-包含在配方中(ids)成分-不包含在配方中(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... 我得到第404页...

How i can make it? 我该怎么做?

PS: I just started learning laravel. PS:我刚刚开始学习laravel。

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. 您可以使用GET参数来满足您的需求test.com/search?country=france&category=breakfast....如果您希望url看起来像/country/***/则可以将其设置为,并在.htaccess文件中进行重写他们获取参数。 And to be sure about order, in search url add some info, for example: test.com/county/france/category/breakfast/**** 为了确保顺序,请在搜索网址中添加一些信息,例如: test.com/county/france/category/breakfast/****

Duplicate of: https://stackoverflow.com/a/21526071/2420002 . 重复项: 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 
        }
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM