Laravel 4 - Can't retrieve data in a one-to-many relationship

前端 未结 5 1409
故里飘歌
故里飘歌 2021-01-21 18:45

I have a Quote model:

class Quote extends Eloquent {

    public function quote_lines() {
        return $this->hasMany(\'QuoteLine\');
    }    

}
         


        
5条回答
  •  执念已碎
    2021-01-21 19:37

    like @Virtlink and @TonyArra said this error is fixed if you use camelCase name in relation functions (this solution worked for me). For example I had

    public function origin_city()
    {
        return $this->belongsTo('City', 'origin_city_id');
    }
    

    This was not working, then I changed it to

    public function origincity()
    {
        return $this->belongsTo('City', 'origin_city_id');
    }
    

    and it didn't work. Only when I used camel case conventions did it work

    public function originCity()
    {
        return $this->belongsTo('City', 'origin_city_id');
    }
    

    Hope it helps others

提交回复
热议问题