php - How the Laravel controller method get the parameters? -
i studying laravel controller methods. in controller methods, there parameters, not coming route parameters. example,
public function store(request $request) { $this->validate($request, [ 'title' => 'required|unique|max:255', 'body' => 'required', ]); }
how laravel controller method parameters? provided parameter $request
? how laravel differentiate route parameters , type of parameters?
what see called dependency injection. before laravel calls store()
method, analyses it's signature phps reflection capabilities , resolves parameters type-hint class through ioc container. that's how current request injected automatically.
after parameters resolved, route parameters passed. because type-hinted arguments resolved first doesn't matter whether @ beginning, in middle or @ end of argument list. case matters optional route parameters:
doesn't work:
public function store($foo = 'bar', request $request){
works:
public function store(request $request, $foo = 'bar'){
Comments
Post a Comment