Php 如何自动解析Laravel管线中模型实例的id
使用Laravel 5(dev/master)是否可以让Laravel自动加载具有id的双功能模型?类似于symfony2注释的东西Php 如何自动解析Laravel管线中模型实例的id,php,laravel,laravel-5,Php,Laravel,Laravel 5,使用Laravel 5(dev/master)是否可以让Laravel自动加载具有id的双功能模型?类似于symfony2注释的东西 class MyController { public function show($id, MyModel $model) { // I'm hoping $model->id == $id if it exists } } 是的,它叫 在您的RouteServiceProvider::before方法中,使用$router->mod
class MyController {
public function show($id, MyModel $model) {
// I'm hoping $model->id == $id if it exists
}
}
是的,它叫
在您的RouteServiceProvider::before
方法中,使用$router->model
进行设置:
public function before(Router $router, UrlGenerator $url) {
$router->model('user', 'User');
}
然后,每当您有一个名为
user
的参数时,它都会自动被替换为user
的实例。无论如何,要通过laravel 5中的注释(如symfony@ParamConverter annotation)来实现这一点,我不这么认为。如果有,我相信至少会在文件中提到。