I have noticed that sometimes, depending on the order that I inject the dependencies, they do not work ...
Is there a correct order?
I have noticed that sometimes, depending on the order that I inject the dependencies, they do not work ...
Is there a correct order?
In constructor , any dependency can be resolved and does not have an order, but when the resolution is done by methods the order is relative to the route parameters, which will always be after all the dependencies that need to be resolved, example :
Route:
Route::post('save/{id}', 'AdminController@save');
Route::post('view/{id}/{slug}', 'NoticeController@view');
Method:
public function save(Request $request, $id)
{
}
public function view(Request $request, RepositoryNotice $repository, $id, $slug)
{
}
then the route params are always placed at the end of the method, explanation is in the documentation
References Dependency Injection & Controllers