Ajax requests
Index requests
Ajax requests made to the server return a different response to HTTP requests.
Where HTTP requests return the view for the index, an Ajax request will return paginated data relevant to that endpoint.
Table requests
If you provide a 'table' property on your ajax request, the data format that you will receive will look like:
{
status: 'success',
data: {
'total' => 19,
'items' => [
{
... // item data
},
{
... // item data
}
]
]
}
In this scenario, item data will be determined by Yadda\Enso\Crud\Resources\TableResource, which by default will return the model's toArray() data (after they have been run through the controller transformers to add index actions etc).
You may change this functionality by overriding the makeTableCollection function on the Crud Controller for that endpoint.
List requests
Any other request to this endpoint will be assumed to be a list request. These requests are designed to return a basic subset of data for listing items, such as within a select box. Your data structure will look like:
{
data: [
{
id: 1,
label: "Item Name",
url: null,
},
];
}
In this scenario, item data will be determined by Yadda\Enso\Crud\Resources\ListResource.
Id will be the result of calling getKey() on the model.
Label, by default, is either the model's name column if not null, falling back to it's title column if not null, finally falling back to getKey(). This functionality my be changed by overriding the model's getCrudLabel function.
Url is null by default. If your list data requires a URL, You may provide it here by overriding the model's getUrl function. This will be the case for fields that lets you select and link other site content.
You may also override the whole data struture by overriding the makeListCollection function on the Crud Controller for that endpoint.
Error responses
If you the user does not have read access to the endpoint. A generic 403 response will be returned.
Should any other error occur during one of these requests, an error message will be returned. These have a code of 500 and the format:
{
status: "error",
message: "Error message describing the thing that went wrong, if possible"
}