First create an interface file TestInterface.php
file.
Create two Repository
files to specifically implement the TestInterface
interface.
Bind
is added to providers
in the app.php
file.
Controller writing
Question: Refer to the writing method in my controller. If this is the case, then there is not much meaning in writing the interface. Even if there is no interface file, I can use two Repository# Methods in ##. Please give me some advice on the correct way to open the controller.
If I use the interface in the controller like this, how to use it, thank you guys!
漂亮男人2017-06-30 09:56:09
Personally, I feel that the warehouse model mentioned in various laravel tutorials on the Internet is only suitable for encapsulating some complex query operations, and is useless for others. The complete warehouse model needs to cooperate with the domain model. In laravel, the model cannot play the role of the domain model. Moreover, there is basically no decoupling operation between the warehouse and Laravel's own ORM, so it is of little significance to define an interface for the model.
Of course, these are just personal understandings, and discussion is welcome. Still need to learn relevant knowledge about domain-driven design
PHP中文网2017-06-30 09:56:09
Not going to discuss this warehouse pattern, the interface should be injected into the controller constructor part of your code