我是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?