ziben69
145
2
Laravel

Photos belonging to a specific position in the row

Posted 3 months ago by ziben69

Hello guys, how can I display photos belonging to a specific position in the row. For example I have table Education, and in it a line about id = 1;

I have something like that:

show.blade.php:

<div class="thumbnail">
     <h3>{{ $education->title }}</h3>
           <div class="caption">     
                      <p>{!! $education->description !!}</p>
           </div>                    
           @foreach($education->photos() as $photo)
           {{ $photo->filename }}
           @endforeach
</div>

Photos() relationship with Education:

 public function photos()
    {
        return $this->hasMany(Photo::class);   
    }

it didn't work so I tried something else:

EducationController:

    public function show(EducationRepository $eduRepo, $id){
        $education = $eduRepo->find($id);
        $photos = $eduRepo->find($id)->photos();

        return view('pages.education.show', [
            "education" => $education,
            "photos" => $photos,
        ]);
    }

Show.blade.php view:

 @foreach($photos as $photo)
 {{ $photo->filename }}
 @endforeach

There is no error, but no result. How can I view photos differently for a specific item?

Thanks so much!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.