我有一个多对一的关系来获取每个产品的图像,每个产品都应该有很多图像供用户查看。所以当我这样做的时候,我试图获得带有图像的股票
public function getImages() {
$stocks = Stocks::with('images', 'tags')->get();
return $stocks;
}
它返回这个
[
{
"id": 7,
"name": "1",
"descriptions": "1",
"price": 1,
"discount": 1,
"category": "new",
"quantity": 1,
"brand": "1",
"created_at": "2019-08-04 09:07:25",
"updated_at": "2019-08-04 09:07:25",
"images": [
{
"id": 6,
"url": "1564909645iKiw2LkoEcQIIhB4MTZJTUfwTREleWH4wEuvmRPd.png",
"created_at": "2019-08-04 09:07:25",
"updated_at": "2019-08-04 09:07:25",
"pivot": {
"stocks_id": 7,
"images_id": 6
}
},
{
"id": 7,
"url": "1564909645OVxnM0qmoQayZrP7wq82pTmSj1AwQc9gioyC5L7h.png",
"created_at": "2019-08-04 09:07:25",
"updated_at": "2019-08-04 09:07:25",
"pivot": {
"stocks_id": 7,
"images_id": 7
}
}
],
"tags": [
{
"id": 1,
"tag": "عطور",
"created_at": "2019-08-03 17:45:52",
"updated_at": "2019-08-03 17:45:52",
"pivot": {
"stocks_id": 7,
"tag_id": 1
}
}
]
}
]
但我希望“图像”只有 url 作为字符串,例如:
"images":[1.png,2.png,3.png .....]
我该怎么办?
我的关系
public function images()
{
return $this->belongsToMany('App\Images', 'stock_images');
}
喵喵时光机
拉风的咖菲猫
holdtom