Skip to content

Commit cda25af

Browse files
qrazibrandonkelly
authored andcommitted
Add includes and excludes support to endpoint configuration (#42)
Resolves #40
1 parent 7af75be commit cda25af

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Possible values are:
208208
The [include names](http://fractal.thephpleague.com/transformers/#including-data) that should be included for the current request, if any.
209209

210210
```php
211-
'includes' => craft()->request->getQuery('include'),
211+
'includes' => Craft::$app->request->getQueryParam('include'),
212212
```
213213

214214
Note that this setting requires a custom transformer class that’s prepped to handle includes:
@@ -218,9 +218,9 @@ class MyTransformerClassName extends TransformerAbstract
218218
{
219219
protected $availableIncludes = ['author'];
220220

221-
public function includeAuthor(EntryModel $entry)
221+
public function includeAuthor(Entry $entry)
222222
{
223-
return $this->item($entry->author, function(UserModel $author) {
223+
return $this->item($entry->author, function(User $author) {
224224
return [
225225
'id' => $author->id,
226226
'name' => $author->name,

src/controllers/DefaultController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ public function actionIndex(string $pattern)
129129
}
130130

131131
$fractal->setSerializer($serializer);
132+
133+
// Set the includes
134+
$fractal->parseIncludes($config['includes'] ?? []);
135+
136+
// Set the excludes
137+
$fractal->parseExcludes($config['excludes'] ?? []);
138+
132139
$data = $fractal->createData($resource);
133140

134141
// Fire a 'beforeSendData' event

0 commit comments

Comments
 (0)