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

前端 未结 5 1355
故里飘歌
故里飘歌 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:23

    At the very least, it should be returning an empty eloquent object.

    In your QuoteLine model, make sure you are telling Eloquent your table name.

    public $table = 'quote_lines';

    In setting up your relationship on your Quote model, be sure it knows what your foreign key is to link to your quote_lines table.

    return $this->hasMany('QuoteLine','quote_line_id');

提交回复
热议问题