INJECTING SERVICES IN BLADE TEMPLATES
In certain rare scenarios, you should create an instance of a class and call its methods directly within a Blade view, rather than from a controller. For these cases, Laravel provides the convenient @inject directive:
@inject('metrics', 'App\Services\MetricsService')<div>Monthly Revenue: {{ $metrics->monthlyRevenue() }}.</div>
AI Assistant
Choose AI provider
Text Tools
Make content clear and easy to read
Have a Question?
Get clear answers based on this content