-1
我有兩個表:Laravel加入相關產品圖像
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');
}
}
這很好。你有什麼嘗試? – Joe 2014-09-24 08:09:05
您應該閱讀關於Laravel文檔中的關係http://laravel.com/docs/4.2/eloquent#relationships – 2014-09-24 08:15:02
不清楚您的問題是什麼,或者您的問題......閱讀文檔,嘗試和詢問何時遇到特定問題。 – 2014-09-24 09:00:50