jeudi 22 août 2019

Laravel API - paginate - return json error

I want to do paging at the Laravel API. As a result, I want to get data and status code type.

STATUS 1

Controller :

public function index()
{
    $data = PersonCollection::collection(Person::paginate(2));

    return response()->json($data, 200);
}

Resource :

    public function toArray($request)
{
    return [
        'id' => $this->id,
        'first_name' => $this->first_name,
        'last_name' => $this->last_name,
        'email' => $this->email,
        'phone' => $this->phone,
        'city' => $this->city,
        'href' => [
            'link' => route('person.show', $this->id),
        ],
    ];
}

Output :

https://i.hizliresim.com/LvlBzj.png


But I want.

https://i.hizliresim.com/LvlBWo.png

I want other page links. But when I convert it to JSON data, links and metadata do not come.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire