Skip to content

Commit

Permalink
Merge branch '5.7' of https://github.com/r3oath/docs-1 into r3oath-5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 19, 2018
2 parents e7f482b + c3a9583 commit 2b2b7b9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions eloquent-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ Once the resource collection class has been generated, you may easily define any
];
}
}

As used above, `$this->collection` is automatically populated with the results of mapping each item of the collection over its singular resource. The singular resource is assumed to be defined as start of the collection's class name, without the trailing string `Collection` – for example `UserCollection` will search for the singluar resource `User`.

You can define `$this->collects` to override this default behaviour:

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class UserCollection extends ResourceCollection
{
public $collects = 'Member';
public function toArray($request)
{
// ...
}
}

After defining your resource collection, it may be returned from a route or controller:

Expand Down

0 comments on commit 2b2b7b9

Please sign in to comment.