3 months ago

Changing the data wrapping when returning json

Posted 3 months ago by lavina

Hello guys, i am trying to return a select from my database, the resource collection class: public function toArray($request) {

    //return parent::toArray($request);
    return [
        'id' => $this -> id,
        'name' => $this -> name,
        'description' => $this ->description,

And then call in controller: public function index(): CompanyResourceCollection { return new CompanyResourceCollection(Company::all()); }

And i get a return of:

"data": [ { "id": 7, "name": "Xzavier Koelpin", "description": "Nemo et vel voluptatem." },

How can i change the wrapping name data to be anything i want?

Please sign in or create an account to participate in this conversation.