The data inside. public function index()
How to give HomeController.php the insidepublic function index()
It's ProductController.php inside.
$types = TypeSml::all();$type = Type::all();view()->share('types', $types);view()->share('type', $type)
HomeController.php怎么调 ProductController.php 里面的 数据呢
Reply content:
The data inside. public function index()
How to give HomeController.php the insidepublic function index()
It's ProductController.php inside.
$types = TypeSml::all();$type = Type::all();view()->share('types', $types);view()->share('type', $type)
HomeController.php怎么调 ProductController.php 里面的 数据呢
view()->shareis to share the data to all views.
Only a single controller is requested each time, and the data is finally given to the view by the controller, why do you share the data directly in the controller?
If you are doing this for code reuse, there are 2 methods:
1. Define the base class controller, the other controller inherits the base class controller;
2. Encapsulate the business logic as a command, which controller needs to be called there.
I don't understand why view () has a share function