mardi 2 juin 2020

laravel one to many relationship , not showing data

i have two classes named academy and pitch the pitch can have many academies and the acdemy belongs to one pitch in my show view of the academy i can see the pitch name using this


but in reverse it sont work , i mean i want to list names of acadmies in each pitch

my models

academy model

public function pitch(){
        return $this->belongsTo(Pitch::class ,'pitch_id');
    }

pitch model

public function academies()
    {
        return $this->hasMany(Academy::class);
    }

i tried this but it dont work

 @foreach ($pitch->academies as $academy)
                        <li></li>
                    @endforeach

the error

Column not found: 1054 Unknown column 'academies.pitch_pitch_id' in 'where clause' (SQL: select * from `academies` where `academies`.`pitch_pitch_id` = 5 and `academies`.`pitch_pitch_id` is not null)


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire