If for whatever reason you need a resource in a blade view that you can’t pass through the controller, you have the ability to resolve it in the blade view iteself.
So you go from this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use App\Services\MyService; class GreatController { protected $myService; public function __construct(MyService $myService) { $this->myService = $myService; } public function index() { return view('frontend.index') ->withServiceStuff($this->service->getStuff()); } } |
To this:
frontend/index.blade.php:
1 2 3 4 5 |
@inject('myService', 'App\Services\MyService') <p> Service Stuff: {{ $myService->getStuff() }}. </p> |
Not something you should be using all of the time, but useful in certain circumstances.
Comments by Anthony