我有这个路由:Route::controller('/', 'PearsController');
在 Laravel 中是否有可能让 PearsController 从另一个控制器加载一个方法,这样 URL 就不会'改变?
I have this route: Route::controller('/', 'PearsController');
Is it possible in Laravel to get the PearsController to load a method from another controller so the URL doesn't change?
例如:
// route:
Route::controller('/', 'PearsController');
// controllers
class PearsController extends BaseController {
public function getAbc() {
// How do I load ApplesController@getSomething so I can split up
// my methods without changing the url? (retains domain.com/abc)
}
}
class ApplesController extends BaseController {
public function getSomething() {
echo 'It works!'
}
}
您可以使用(仅限 L3)
You can use (L3 only)
Controller::call('ApplesController@getSomething');
在L4
中你可以使用
$request = Request::create('/apples', 'GET', array());
return Route::dispatch($request)->getContent();
在这种情况下,你必须为ApplesController
定义一个路由,就像这样
In this case, you have to define a route for ApplesController
, something like this
Route::get('/apples', 'ApplesController@getSomething'); // in routes.php
在 array()
中,如果需要,您可以传递参数.
In the array()
you can pass arguments if required.
这篇关于Laravel:在另一个控制器中加载方法而不更改 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!