我有一個報價模型無法檢索數據:Laravel 4 - 在一個一對多的關係
class Quote extends Eloquent {
public function quote_lines() {
return $this->hasMany('QuoteLine');
}
}
並有QuoteLine模型:
class QuoteLine extends Eloquent {
public function quote() {
return $this->belongsTo('Quote');
}
}
我對這種模式表quote_lines。
模式:
Schema::create('quote_lines', function($table)
{
$table->increments('id');
$table->integer('quote_id');
$table->string('title');
$table->string('desciption');
$table->integer('quantity');
$table->decimal('unit_price', 5, 2);
$table->timestamps();
});
Schema::create('quotes', function($table)
{
$table->increments('id');
$table->integer('contact_id');
$table->integer('company_id');
$table->timestamps();
});
的事情是我不能似乎從我的報價單控制器訪問報價行:
$quote_lines = Quote::find($id)->quote_lines;
dd($quote_lines);
只是返回NULL
所以,我有shoppingMalls()期待成爲像$ this-> shopping_malls這樣的動態屬性,但不是,它會返回null。任何人都知道在未來的laravel版本中是否會發生變化? –
@JosePalazuelos是shopping_malls一個屬性或關係?一個屬性需要方法名稱getShoppingMallsAttribute() – TonyArra
這是一種關係,我沒有一個名爲shopping_malls的屬性。我不知道爲什麼不轉換成snake_case。我只是將名稱改爲一個詞,只是爲了按預期工作。 –