I'm confused about why we need constructor and can someone explain me about this code from my controller :
public function __construct(MerchantService $merchantService, PaymentService $paymentService){
$this->merchantService = $merchantService;
$this->paymentService = $paymentService;
}
I am working on an admin panel with laravel . and our boss wants the stucture to be like this:
controller -> service -> repository -> modal -> database
it's pretty straight forward when i am going this route:
controller -> modal ->database.
but i have to follow the first one. The above code is a sample from the controller
in the above code there are 2 services, MerchantService
and PaymentService
. but i do not understand what exactly is the constructor doing with the Merchant service
variable and payment variable as params, is it initiating an object of Merchant service
and PaymentService
??