我有一个资源正在向其发送2个其他数据,这些数据是2个数组,如下所示:
这是我的资源:
/**
* @var
*/
private $foo;
/**
* Create a new resource instance.
*
* @param mixed $resource
* @return void
*/
public function __construct($resource, $hasroom,$hasdate)
{
// Ensure you call the parent constructor
parent::__construct($resource);
$this->resource = $resource;
$this->hasroom = $hasroom;
$this->hasdate = $hasdate;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{ return [
'hasroom' => $this->hasroom,
'hasdate' => $this->hasdate,
];
}
}
这是我从控制器发送附加数据的地方:
return new BookingStatusResource($dates, $hasroom,$hasdate);
这是我得到的输出:
{
data: {
hasroom: [
1,
2,
3,
4,
5
],
hasdate: [
"2019-03-31T19:30:00.000000Z",
"2019-03-31T19:30:00.000000Z",
"2019-04-01T19:30:00.000000Z",
"2019-04-01T19:30:00.000000Z",
"2019-04-02T19:30:00.000000Z",
]
}
}
但这是我想从输出中接收的格式:
{
data: {
{
'hasroom':1,
'hasdate':"2019-03-31T19:30:00.000000Z"
},
{
'hasroom':2,
'hasdate':"2019-03-31T19:30:00.000000Z"
},
}
我想知道如何合并这两个数组,并在我的资源中将它们彼此相邻显示。