ResourceCollection is not providing a ResourceCollection
I'm trying to provide a collection of my tables to display for a Bulk (index) or all my tables in the database...
There appears to be a bug causing the ResourceCollection to not work, What should I check?
Resource\Order.php
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class Order extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => $this->collection,
];
}
}
ResourceCollection is returning this incorrect Json response?
// 20191017103310
// http://domain.test/api/middleware/orders/bulkindex
[
{
"data": {
"connection": {
},
"grammar": {
},
"processor": {
},
"bindings": {
"select": [
],
"from": [
],
"join": [
],
"where": [
],
"having": [
],
"order": [
],
"union": [
],
"unionOrder": [
]
},
"aggregate": null,
"columns": null,
"distinct": false,
"from": "orders",
"joins": null,
"wheres": [
],
"groups": null,
"havings": null,
"orders": null,
"limit": null,
"offset": null,
"unions": null,
"unionLimit": null,
"unionOffset": null,
"unionOrders": null,
"lock": null,
"operators": [
"=",
"<",
">",
"<=",
">=",
"<>",
"!=",
"<=>",
"like",
"like binary",
"not like",
"ilike",
"&",
"|",
"^",
"<<",
">>",
"rlike",
"not rlike",
"regexp",
"not regexp",
"~",
"~*",
"!~",
"!~*",
"similar to",
"not similar to",
"not ilike",
"~~*",
"!~~*"
],
"useWritePdo": false
}
},
{
"data": {
"connection": {
},
"grammar": {
},
"processor": {
},
"bindings": {
"select": [
],
"from": [
],
"join": [
],
...
ETC...
Please note I can change it to a JsonResource and it works as expected...
EDIT: api.php (route)
Route::get('/orders/bulkindex/', function () {
return OrderResource::collection(Order::all());
});
EDIT:
use App\Http\Resources\Cart as CartResource;
return [
'data' => $this->collection,
'carts' => CartResource::collection($this->carts), // CODE DOES NOT WORK
];
I get this error message:
Property [carts] does not exist on this collection instance.
Resources\Cart.php
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class Cart extends ResourceCollection
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}
OrderorOrderResource? - Salim Djerbouh