在Laravel 5中将路由器注入控制器方法

Does anyone know why can't one use controller method injection in Laravel 5 to make the $router singleton available inside a controllers method, like in the code below?

use Illuminate\Routing\Router;

class WelcomeController extends Controller {
    // ...
    public function test($name = 'default var value', Router $router)
    {
        // stuff like taking the {name} part of /say-hello-to/{name?}
        // ...using $router->input('name') for example
        // ...assuming a route like: Route::get('say-hello-to/{name?}', 'WelcomeController@test') 
    }
}

An alternative way to get the same thing (idiomatic access to an url part inside a controller method) is useful, but I've already thought of a way to do this and I'm mainly interested in why this doesn't just work, as what I'm trying to get is a deeper understanding of how Laravel works and what advanced patterns can one emply when working with it.

查看全部
duanping1920
duanping1920
2014/12/07 13:39
  • laravel
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复