Home > database >  Laravel blade render crashes the img src using asset()
Laravel blade render crashes the img src using asset()

Time:05-22

I stored my HTML in database in which i have some images and the src is given by laravel asset helper but while rendering it on view using laravel html renderer {!! !!} the {{asset("img/abc.jpg")}} in src attribute of img tag is not working it's shown in the same way in src.

CodePudding user response:

Since the template is not in a view Laravel won't know that it contains Blade syntax, so you'll have to render it manually:

use Illuminate\Support\Facades\Blade;
 
return Blade::render('Hello, {{ $name }}', ['name' => 'Julian Bashir']);

Source: Laravel Docs - Rendering Inline Blade Templates

CodePudding user response:

I think you are doing something wrong. if asset("img/abc.jpg") is stored in database, you actually have saved the blade engine template, not the rendered HTML. In the rendered HTML, you should have something like this:

<img src="http://127.0.0.1:8000/img/abc.jpg">

instead of asset("img/abc.jpg"), which doesn't need any further coding.

  • Related