如何在不写入 Routes.php 文件的情况下指向 Controller 中的不同方法。所以,我有一个 Controller 。
class HomeController extends Controller {
public function index()
{
return view('front.home.index');
}
public function business()
{
return view('front.home.business');
}
public function aboutus()
{
return view('front.home.about');
}
这个 Controller 可以有无限的方法,我想调用这些方法而不需要在路由文件中编写每个方法。例如如何在不写入 Routes.php 的情况下调用 home/business 或 home/aboutus。目前我正在这样做。
Route::get('/home', 'HomeController@index');
Route::get('/home/business', 'HomeController@business');
Route::get('/home/aboutus', 'HomeController@aboutus');
最佳答案
如果您以这种方式更改 Controller 中的方法名称:
index => getIndex
business => getBusiness
aboutus => getAboutus
然后您可以使用:
Route::controller('home', 'HomeController');
关于php - Laravel 5 中 Controller 中方法的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29327293/