【发布时间】:2014-07-30 14:11:39
【问题描述】:
我正在尝试使用 Eloquent 获取具有映射到 brands 表的 brand_id 列的特定产品,brand 数组返回为空。
这里有什么明显的地方需要改变吗?
$product = Product::with('images')->with('brand')->select($fields)->where('display', '=', 1)->find($id);
//产品型号
class Product extends Eloquent {
...
public function brand()
{
return $this->belongsTo('Brand');
}
//品牌型号
class Brand extends Eloquent {
...
public function products()
{
return $this->hasMany('Product');
}
【问题讨论】:
-
你检查过:$brand = $product->brand(); ?
-
$fields变量中有哪些字段?
标签: php mysql orm laravel eloquent