I\'m trying to create a blade directive to highlight some words that will return from my search query.
This is my blade directive:
class AppServiceProvid
I found an alternative approach to accessing View variables within a Blade Directive.
I wanted to check whether a given string appeared as an array key in a variable accessible in the view scope.
As the Blade Directive returns PHP which is evaluated later, it is possible to 'trick' the Directive by breaking up a variable name so that it doesn't try to parse it.
For example:
Blade::directive('getElementProps', function ($elementID) {
return "";
});
In this example we have split the $elementData variable name so the Blade Directive treats it like a spring. When the concatenated string is returned to the blade it will be evaluated as the variable.