Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
Because property photos.name comes back to me as if I'm doing it wrong?

I'm having an error with vue.js and laravel but I can't figure out how can I get this array/object inside coded in a nutshell I connected to the room the instance photos via the has many of laravel and the output in the api call is like this :

Photos

I would like to just get the name from inside photos and then bring it into the frontend but every time I do that it tells me undefined as if I'm doing wrong method of entry.

Code frontend :

 <div class="col-md-3" v-for="(room, index) in rooms" :key="index">
                <div class="card mb-3 border-0">
                    **<img :src="'/img/rooms/'+room.photos.name" class="card-img-top br0" :alt="room.photos.name">**
                    
                    <p class="small text-uppercase pb-0">{{ room.listing_name }}</p>
                    <div class="card-body p-0">

                        <h5 class="card-title">{{ room.listing_name }}</h5>
                        <p class="card-text m-0">${{ room.price }}/night</p>
                        <p class="small m-0 text-info">&#9733;&#9733;&#9733;&#9733;&#9733;
                        <span class="text-secondary"> {{ index }}, Superhost</span></p>
                    </div>
                </div>
            </div>

front-end

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

photos is an array:

<img :src="'/img/rooms/'+room.photos[0].name" class="card-img-top br0" :alt="room.photos[0].name">

Or you can iterate:

<img v-for="photo in room.photos" :src="'/img/rooms/'+photo.name" class="card-img-top br0" :alt="photo.name">
about 4 years ago · Juan Pablo Isaza Relatório

0

photos is an Array of objects. Hence, Elements should be access via index.

You have to add one more iteration for photos via v-for.

<img v-for="photo in room.photos"
 :key="photo.id"
 :src="`/img/rooms/${photo.name}`"
 class="card-img-top br0"
 :alt="photo.name"
/>
about 4 years ago · Juan Pablo Isaza Relatório

0

The image tag should be something like this:

<img src="/img/rooms/{{room.photos.name}}" alt="">
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda