You can manually create the meta and links properties using the Paginator instance. Here's an example:
$perPage = 10;
$page = request()->get('page', 1);
$offset = ($page - 1) * $perPage;
$query = DB::table('my_table')->offset($offset)->limit($perPage)->get();
$total = DB::table('my_table')->count();
$paginator = new LengthAwarePaginator($query, $total, $perPage, $page);
$meta = [
'current_page' => $paginator->currentPage(),
'from' => $paginator->firstItem(),
'last_page' => $paginator->lastPage(),
'path' => request()->url(),
'per_page' => $perPage,
'to' => $paginator->lastItem(),
'total' => $paginator->total(),
];
$links = [
'first' => $paginator->url(1),
'last' => $paginator->url($paginator->lastPage()),
'prev' => $paginator->previousPageUrl(),
'next' => $paginator->nextPageUrl(),
];
$response = [
'data' => $query,
'meta' => $meta,
'links' => $links,
];
return response()->json($response);
In this example, we manually create a LengthAwarePaginator instance using the query builder result, total count, and pagination parameters. Then, we create the meta and links properties using the paginator instance methods. Finally, we return a JSON response with the data, meta, and links properties.