Where to connect to change the view of the output in Laravel 5?
For some kind of output filter, I need to access the final output line of the output, which includes both the view data and the "hardcoded" texts in the view file.
For example:
welcome.blade.php
<div>This is bad and you are {{ $variable }}</div>
controller, composer or whatever that binds variables
view()->with('variable', 'bad')
The end result will be
<div>This is bad and you are bad</div>
But now let's pretend we want to replace every instance of "bad" with "good", so we get:
<div>This is good and you are good</div>
Changing view data is well supported, but how do you apply some change logic to fully rendered content? (since I think this is the only way to change the content of the view file itself?)
Note: if and only if possible, I would prefer "hooking" instead of "expansion kernel".
source to share
Take a look at CompilerEngine (Illuminate \ View \ Engines \ CompilerEngine). You can use it to get the evaluated content of the view using the get method. Perhaps combine this with a registered ServiceProvider to manage the content of the views. Also check out BladeCompiler , maybe you can combine them.
But trying to hardcode it seems a little odd. Why not just use variables in the first place. I mean, why is it hardcoded if you want to change it afterwards?
source to share