Answer the question
In order to leave comments, you need to log in
Laravel. I do not understand the logic of the code?
I am learning from the lessons "Laravel Framework from Zero to Pro" . In principle, everything is clear, except for one code...
IndexController
class IndexController extends SiteController {
public function __construct() {
$menu = new \Corp\Repositories\MenusRepository(new \Corp\Menu);
parent::__construct($menu);
$this->bar = 'right';
$this->template = env('THEME').'.index';
}
}
<?php
namespace Corp\Repositories;
use Corp\Menu;
class MenusRepository extends Repository {
public function __construct(Menu $menu) {
$this->model = $menu;
}
}
?>
parent::__construct(new \Corp\Repositories\MenusRepository(new \Corp\Menu));
public function __construct(Menu new \Corp\Repositories\MenusRepository(new \Corp\Menu))
{
$this->model = $menu;
}
Answer the question
In order to leave comments, you need to log in
What nonsense are you being taught. Better read the doc and watch the laracasts ( https://laracasts.com). No one in the lair does that.
The env function cannot be used in code at all. All environment variables must be transferred to configs and it is desirable to specify default configs.
But in fact, if you do not understand the logic itself, then learn OOP and SOLID
The author of this code does not own php or laravel at the proper level. Better read the original documentation and delete the laracasts. And your question is related to php.
This code calls the constructor of the parent class, while the interface of the inheritor constructor differs from the parent, which violates the principles of SOLID.
php.net/manual/en/language.oop5.decon.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question