Laravel - 在Route中使用两个参数:bind

时间:2018-06-15 17:20:32

标签: php laravel laravel-routing

我是Laravel Framework的新手,我收到了一封带有网址的ajax请求:/translate/cs/abeceda

此链接的路线是:

Route::get('/translate/{lang}/{word}', 'DictionaryController@translate')->name('translateWord');

Route :: bind 是:

class RouteServiceProvider extends ServiceProvider {

   public function boot() {
    //some code

    Route::bind('word', function($word){
        dd(Route::currentRouteName());
        $language = Language::where('code', app()->getLocale())->first();
        if($language){
            if($word = Word::where('word', 'like', '%' . $word . '%')->where('language_id', $language->id)->first()){
                return $word;
            }
            throw new \Exception('Invalid word');
        }
        throw new \Exception('Invalid language');
    });

    parent::boot();
}

}

而不是app()->getLocale()我需要获取网址 lang参数(在本例中为cs)。有没有可能获得lang param?

0 个答案:

没有答案