1 year ago

Photos belonging to a specific position in the row

Posted 1 year 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:


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

Photos() relationship with Education:

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

it didn't work so I tried something else:


    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 }}

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.