Hello,
In my Laravel 8 app I want to add svg files and reading this
https://stackoverflow.com/questions/30058556/including-svg-contents-in-laravel-5-blade-template
I added svg support directive in app/Providers/AppServiceProvider.php :
public function boot()
{
\Blade::directive('svg', function($arguments) {
// Funky madness to accept multiple arguments into the directive
list($path, $class) = array_pad(explode(',', trim($arguments, "() ")), 2, '');
$path = trim($path, "' ");
$class = trim($class, "' ");
// Create the dom document as per the other answers
$svg = new \DOMDocument();
$svg->load(public_path($path));
$svg->documentElement->setAttribute("class", $class);
$output = $svg->saveXML($svg->documentElement);
return $output;
});
and in blade file :
<div class="Login__image Login__cloud">
@svg($countryFlagUrl, 'Cloud')
</div>
and I got error :
DOMDocument::load(): I/O warning : failed to load external entity "/mnt/_work_sdb8/wwwroot/lar/AdsBackend8/public/$countryFlagUrl"
If to comment line
@svg($countryFlagUrl, 'Cloud')
line with $countryFlagUrl output valid path to svg file :
$countryFlagUrl::/images/flags/afg.svg
Looks like var $countryFlagUrl was not rendered inside of the directive.
Which is the valid way ?
Thanks!