mardi 3 août 2021

Laravel vuejs Pagination Ressource/Collection

I have a Pagination resource

public function toArray($request): array
{
    return [
        'current_page' => $this->currentPage(),
        'last_page' => $this->lastPage(),
        'links' => $this->links(),
        'next_page_url' => $this->nextPageUrl(),
        'count' => $this->count(),
        'per_page' => $this->perPage(),
        'prev_page_url' => $this->previousPageUrl(),
        'total' => $this->total()
    ];
}

and a collection

 public function toArray($request):array
{
    return [
        'data'       => $this->collection,
    ];
}

I have tried this one

 public function toArray($request) : Array
{
    $pagination = new PaginationResource($this);

    return [
        'templates' => $this->collection,
        $pagination::$wrap => $pagination,
    ];
}

But the result is like this

        'templates' => $this->$collection(),
        'data' => $pagination,

I want to use the pagination Resource in the collection To have the Result like this

        'data' => $this->collection,
        'current_page' => $this->currentPage(),
        'last_page' => $this->lastPage(),
        'links' => $this->links(),
        'next_page_url' => $this->nextPageUrl(),
        'count' => $this->count(),
        'per_page' => $this->perPage(),
        'prev_page_url' => $this->previousPageUrl(),
        'total' => $this->total()

** Is there any solution to merge them (SortOf) **



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/37fMx0f
via IFTTT

Aucun commentaire:

Enregistrer un commentaire