class ApiSerializer implements ExtenderInterface

Methods

__construct(string $serializerClass)

No description

attribute(string $name, callable|string $callback)

<p>Add a single attribute to this serializer.</p>

attributes(callable|string $callback)

<p>Add to or modify the attributes array of this serializer.</p>

hasOne(string $name, string $serializerClass)

<p>Establish a simple hasOne relationship from this serializer to another serializer.</p>

hasMany(string $name, string $serializerClass)

<p>Establish a simple hasMany relationship from this serializer to another serializer.</p>

relationship(string $name, callable|string $callback)

<p>Add a relationship from this serializer to another serializer.</p>

extend(Container $container, Extension $extension = null)

No description

Details

__construct(string $serializerClass)

Parameters

string $serializerClass <p>The ::class attribute of the serializer you are modifying. This serializer should extend from \Flarum\Api\Serializer\AbstractSerializer.</p>

ApiSerializer attribute(string $name, callable|string $callback)

<p>Add a single attribute to this serializer.</p>

Parameters

string $name
callable|string $callback <p>The callback can be a closure or an invokable class, and should accept:</p> <ul> <li>$serializer: An instance of this serializer.</li> <li>$model: An instance of the model being serialized.</li> <li>$attributes: An array of existing attributes.</li> </ul> <p>The callable should return:</p> <ul> <li>The value of the attribute.</li> </ul>

Return Value

ApiSerializer

ApiSerializer attributes(callable|string $callback)

<p>Add to or modify the attributes array of this serializer.</p>

Parameters

callable|string $callback <p>The callback can be a closure or an invokable class, and should accept:</p> <ul> <li>$serializer: An instance of this serializer.</li> <li>$model: An instance of the model being serialized.</li> <li>$attributes: An array of existing attributes.</li> </ul> <p>The callable should return:</p> <ul> <li>An array of additional attributes to merge with the existing array. Or a modified $attributes array.</li> </ul>

Return Value

ApiSerializer

ApiSerializer hasOne(string $name, string $serializerClass)

<p>Establish a simple hasOne relationship from this serializer to another serializer.</p>

<p>This represents a one-to-one relationship.</p>

Parameters

string $name
string $serializerClass

Return Value

ApiSerializer

ApiSerializer hasMany(string $name, string $serializerClass)

<p>Establish a simple hasMany relationship from this serializer to another serializer.</p>

<p>This represents a one-to-many relationship.</p>

Parameters

string $name
string $serializerClass

Return Value

ApiSerializer

ApiSerializer relationship(string $name, callable|string $callback)

<p>Add a relationship from this serializer to another serializer.</p>

Parameters

string $name
callable|string $callback <p>The callable can be a closure or an invokable class, and should accept:</p> <ul> <li>$serializer: An instance of this serializer.</li> <li>$model: An instance of the model being serialized.</li> </ul> <p>The callable should return:</p> <ul> <li>$relationship: An instance of \Tobscure\JsonApi\Relationship.</li> </ul>

Return Value

ApiSerializer

extend(Container $container, Extension $extension = null)

Parameters

Container $container
Extension $extension