Skip to content

Conversation

@AndreyTheK
Copy link

@AndreyTheK AndreyTheK commented Feb 13, 2023

Sample usage:


class UserController extends ApiController
{

    protected function getBuilder()
    {
        return QueryBuilder::for(User::class)
            ->allowedIncludes([
                ApiIncludes::dummy('foo'),
            ])
        ;
    }
}


class UserResource extends ApiResource
{
    public function toArray($request)
    {
        return [
            'userid' => $this->userid,
            'bar'    => $this->whenIncluded('foo', fn() => 'baz!')
        ];
    }
}
GET /v3/api/users?include=foo

{"data":[{"userid":1149920,"bar":"baz!"},{"userid":1149921,"bar":"baz!"},{"userid":1149922,"bar":"baz!"}, ...

These serve no purpose other than being a placeholder for whenIncluded, allowing us to have simple logic in resource rather than having to define complex relationships in models
@AndreyTheK AndreyTheK marked this pull request as ready for review February 23, 2023 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant