Andreas Hunter
Andreas Hunter

Reputation: 5004

Laravel-5.5: How to write correct path to image in html code using css?

I use method asset() for connect assets to website. Example:

<link href="{{ asset('dist/css/style.css') }}" rel="stylesheet" type="text/css">

And how I can use method asset() in this html code for include images using css:

<div class="attached-img-container" style="background-image:url(dist/img/gallery/equal-size/mock1.jpg)"></div>

List of my routes:

Route::group(['prefix' => 'inbox', 'middleware' => 'auth'], function(){
    Route::get('/', ['uses' => 'InboxController@index',])->name('inbox');
    Route::match(['get', 'post'], '/message/{id?}', ['uses'=>'InboxController@message'])->name('message');
    Route::match(['get', 'post'], '/compose', ['uses'=>'InboxController@compose'])->name('compose');
});

In route inbox assets work from public folder but in message or in compose routes assets not work.

Upvotes: 1

Views: 504

Answers (4)

Rwd
Rwd

Reputation: 35180

You should be able to do:

background-image:url({{ asset('dist/img/gallery/equal-size/mock1.jpg') }})

That being said, if the dist directory is in your public folder, you should be able to add / at the beginning:

background-image:url(/dist/img/gallery/equal-size/mock1.jpg)

Upvotes: 1

Sohel0415
Sohel0415

Reputation: 9853

You could use url() helper function like-

background-image:url({{ url('/dist/img/gallery/equal-size/mock1.jpg') }})

Upvotes: 0

Saurabh Mistry
Saurabh Mistry

Reputation: 13669

no need to use asset() if it is inside public folder , you can directly access it by using /

for example your image is inside public/images/myimage.jpg

then u can use <img src="/images/myimage.jpg" />

<div style="background-url:('/images/myimage.jpg')">

Upvotes: 0

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

You can use absolute path like this:

background-image:url(/dist/img/gallery/equal-size/mock1.jpg)

Upvotes: 0

Related Questions