Answer the question
In order to leave comments, you need to log in
What is the correct way to inject dependencies in laravel controller?
There was a dispute about where it is more correct to specify dependencies in the Laravel controller?
in __construct
ClassController extends Controller {
private $d1;
private $d2;
private $d3;
public function __construct(Dependency1 $d1, Dependency2 $d2, Dependency3 $d3) {
$this->d1 = $d1;
$this->d2 = $d2;
$this->d3 = $d3;
}
public function create() {
$this->d1->send();
$this->d2->send();
}
public function index() {
$this->d3->send();
}
}
ClassController extends Controller {
public function create(Dependency1 $d1, Dependency2 $d2) {
$d1->send();
$d2->send();
}
public function index(Dependency3 $d3) {
$d3->send();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question