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 think you can only pass one parameter. It's not pretty but you could pass your parameters as an array like so:
@highlight(['expression' => 'ho', 'string' => 'house'])
So your directive could be
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Blade::directive('highlight', function($array){
$expressionValues = preg_split('/\s+/', $array['expression']);
foreach ($expressionValues as $value) {
$array['string'] = str_replace($value, "".$value."", $array['string']);
}
return "";
});
}
public function register()
{
}
}
Found it here: https://laracasts.com/discuss/channels/laravel/how-to-do-this-blade-directive