1

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.

4 Answers 4

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use absolute path like this:

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

4 Comments

image in public folder but if I create group of routes with in prefix then assets not working @Marcin
If that's the problem, you should include your routes
How I must include my routes?
Add them into your question
0

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')">

Comments

0

You could use url() helper function like-

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.