所以我正在使用 Laravel 框架在 php 中开发一个 Web 应用程序。我有 12 个模型和 1 个控制器,以及 12 个链接到模型的存储库。在每个存储库中,我都在编写一些带有查询的函数,因此它们不会在控制器中重复。我正在尝试在控制器构造函数中注入存储库,但不知道其中有多少太多?
我听说,它通常是 1 或 2 个,但到目前为止我有 12 个。
控制器:
class PagesController extends Controller {
protected $review;
protected $organization;
protected $user;
protected $city;
protected $buyer;
protected $employee;
public function __construct(ReviewRepository $review, OrganizationRepository $organization, UserRepository $user, CityRepository $city, BuyerRepository $buyer, EmployeeRepository $employee) { //here are just 6 repositories, I have much more
$this->employee = $employee;
$this->city = $city;
$this->buyer = $buyer;
$this->user = $user;
$this->organization = $organization;
$this->review = $review;
}
存储库:
class ReviewRepository {
protected $review;
function __construct(Review $review)
{
$this->review = $review;
}
}