Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alaa15's avatar

make background-image: url(); work in laravel

if i have in my css file a background-image: url(); , how to make it work in laravel5 , no photo appear .

0 likes
10 replies
z.zabawa175@gmail.com's avatar

@Snapey - Well can you make it a dynamic path, this doesn't work on my production site, but this could be because I have to include the root in my path to get what you suggest to work in development site

background-image: url("/storybox1.0/public/img/BCsatBlack.png");

1 like
Snapey's avatar

Then you have your server configured incorrectly. your site name and public should not be visible. The web server root (/) needs to be the contents of the public folder.

1 like
acidkiwi's avatar

What if you have the image stored in S3?

From blade you would use: <img src="{{ Storage::disk(env( 'DISK', 'local'))->url('whatever.png') }}">

... defining DISK and local in you env. But how do you do that in a css?

jhc333's avatar

You have to compile your CSS using a tool like LESS or SASS with Gulp. That would allow you to put the path to storage in a variable, same as you do with PHP.

Snapey's avatar

@jhc333 beg to differ. You cannot run PHP code in your LESS or SASS files.

rebirthtobi's avatar

@Alaa15 you can still make use of your relative path in your css, place your css and images that are being used inside the public folder and then use your relative path.

Michirah's avatar

You can use inline CSS in a laravel blade as below:

style="background-image: url('{{ asset('assets/images/b2b/graph-01.svg')}}');"

8 likes

Please or to participate in this conversation.