Answer the question
In order to leave comments, you need to log in
Is it a good solution to output the result from the controller directly in the blade template?
I am new to Laravel, in the process of creating a site, it became necessary to create a module responsible for displaying a horizontal, vertical menu of categories and sections of the site, including the footer of the site. I note that by module I mean a site component that can be connected and displayed anywhere in the template.
I created a controller, a class for the controller, my own templates for the controller.
And I output in the template, in the place I need, the result with such a line of code, for example, in header.blade.php:
{{(new App\Http\Controllers\MenuController)->init('horizontal')}}
Answer the question
In order to leave comments, you need to log in
In such cases it is better to use inject
@inject('metrics', 'App\Services\MetricsService')
<div>
Monthly Revenue: {{ $metrics->monthlyRevenue() }}.
</div>
And what does not fit the option through the service provider? In such cases, I just write to the AppServiceProvider
view()->composer(['header', 'footer'], function($view){
$view->with('menus', Menu::all());
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question