【发布时间】:2014-11-18 15:24:01
【问题描述】:
我有两张桌子:
product:id | name | category
productimage:id | imagename | productid
我想以这种形式获取结果:
[{
"id":1,
"name":"abc",
"category":1,
"imagename":[
{
"id":1,
"imagename":abc.jpg
},
{
"id":2,
"imagename":abc1.jpg
},
{
"id":3,
"imagename":abc2.jpg
}]
}]
我有两个模型:
call:
= product
= productimage
<?php
class Product extends \Eloquent {
//protected $fillable = [];
protected $table = 'product';
public function productimage(){
return $this->hasMany('productimage');
}
}
<?php
class Productimage extends \Eloquent {
//protected $fillable = [];
protected $table = 'productimage';
public function product(){
return $this->belongsTo('product');
}
}
【问题讨论】:
-
很好。你试过什么?
-
你应该阅读 Laravel 文档中的关系 laravel.com/docs/4.2/eloquent#relationships
-
不清楚您的问题是什么,或者您的问题...阅读文档,尝试,并在遇到特定问题时询问。
-
我的问题不知道怎么加入product::find(id)->productimage;
标签: php mysql sql laravel eloquent