skip to Main Content

I am new to Laravel.

I am trying to show the MySQL image in the background but I can’t.

I have used this code to show but it is not working at all

<div class=" banner-services-bg"style="background-image: url('{{ $pageData->image }}');">

I want to tell you that I can see $pagedata with the dd() function and the image is also there
and I have public>images folder structure

and also I can see my image directly on the page with this code

<img src="{{ url($pageData->image) }}"alt="" />

attributes i got through dd function

#attributes: [▼
"id" => 36
"title" => "Best Car Rental Offers"
"slug" => "car-rental"
"image" => "uploads/1/2023-03/car_with_driver.jpg"
]

2

Answers


  1. Chosen as BEST ANSWER

    I have used this code

    style="background-image: url({{ url($pageData->image) }});"
    

    and now i can see my database image as a background

    thanks to all who reply on my post


  2. There are two main resons!

    1. Your div has 0 width and height!
    2. Your image address escaped!

    Try this:

    <div class=" banner-services-bg" style="width: 100%; aspect-ratio: 1 / 1; backgriund-size: cover; background-image: url('{!! $pageData->image !!}');">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search