Hi friend, I have the same problem as you, did you manage to find a solution?
Showing data from http request in laravel nova
Hi, I'm newbie in laravel nova (also in php at all) and I have an issue, I need to show resource for data, that is not stored in my DB, either it is stored is another server, that provided http route. Now, I want to know, where is query that is builded step by pagination, filters and etc is called and override this method, like:
class MyClass extends Resource
{
....
public function foo($query, ...)
{
// $data = query->get();
$data = Http->get('my_url.com');
...
}
}
P.S.: I have tried implement sushi for storing data in temp sqlLite db, but it doesn't filtered data correctly (I need to do new request each time when filters, page or search are changed, but I can't provide filter values to getRows correctly) and also serializeForIndex overriding doesn't helped (code was generated by chatGPT and it has mistakes, but I don't know right way).
Code of serializeForIndex
public function serializeForIndex(NovaRequest $request, $fields = null)
{
$page = $request->page ?? 1;
$perPage = $request->perPage ?? 25;
$data = Core::MyRequest(
// filters and pagination are provided
);
if (count($data) === $perPage) {
$total = $page * $perPage + 1;
} elseif (count($data) === 0 && $request->page > 1) {
$total = ($page - 1) * $perPage;
} else {
$total = $page * $perPage;
}
return [
'resources' => collect($data)->map(function ($item) {
return [
// converted response to pretty look
];
}),
'total' => $total,
'per_page' => $perPage,
];
}
Please or to participate in this conversation.