ResourceCollection не предоставляет ResourceCollection
Я пытаюсь предоставить коллекцию моих таблиц для отображения для Bulk (индекса) или всех моих таблиц в базе данных ...
Кажется, есть ошибка, приводящая к тому, что ResourceCollection не работает, что я должен проверить?
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 возвращает этот неправильный ответ Json?
// 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...
Обратите внимание, что я могу изменить его на JsonResource, и он будет работать как положено ...
РЕДАКТИРОВАТЬ: api.php (маршрут)
Route::get('/orders/bulkindex/', function () {
return OrderResource::collection(Order::all());
});
РЕДАКТИРОВАТЬ:
use App\Http\Resources\Cart as CartResource;
return [
'data' => $this->collection,
'carts' => CartResource::collection($this->carts), // CODE DOES NOT WORK
];
Я получаю это сообщение об ошибке:
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);
}
}