我有这个路由这是伟大的工作:Laravel路由愁楚
Route::get('/', '[email protected]');
Route::get('about', '[email protected]');
Route::get('contact', '[email protected]');
Route::get('signUp', '[email protected]');
在MainController.php
正确的功能得到预期调用。
当我遇到麻烦的是在得到以下工作:
我有一个新的文件名为APIController.php
。所有请求http://eamorr.com/api/getUsers应该由getUsers()
处理APIController.php
。
我尝试这样做:
Route::get('api', '[email protected]'); //this works fine...
Route::any('api/{$function}', function($function){ //but this won't work!
return redirect()->route('api/'.$function);
});
我不想列出每一样功能:
Route::get('api/addUser', '[email protected]');
Route::get('api/getUser', '[email protected]');
Route::get('api/getAllUsers', '[email protected]');
...
我宁愿如果/api/*
请求一下就指向APIController ...
如果有人有任何提示,这将是非常棒的...
我只昨天开始学习Laravel,所以请放轻松点!
我相信你需要从路由模式中省略'$'。 http://laravel.com/docs/5.0/routing#route-parameters –
@GerardvanHelden是的,你是正确的 - 一个容易犯的错误,为一个新人。但它仍然不起作用。我认为'return redirect() - > route('api /'。$ function);'不正确。而我无法弄清楚我应该返回什么...... – Eamorr
请问为什么你不想列出每个功能?在我看来,将所有可能的路由明确地集中在一个地方是laravel路由的优点之一.. –