class ApiSerializer implements ExtenderInterface

Methods

__construct(string $serializerClass)

No description

attribute(string $name, $callback)

No description

attributes(callable|string $callback)

Add to or modify the attributes array of this serializer.

mutate(callable|string $callback) deprecated

Add to or modify the attributes array of this serializer.

hasOne(string $name, string $serializerClass)

Establish a simple hasOne relationship from this serializer to another serializer.

hasMany(string $name, string $serializerClass)

Establish a simple hasMany relationship from this serializer to another serializer.

relationship(string $name, $callback)

Add a relationship from this serializer to another serializer.

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

No description

Details

__construct(string $serializerClass)

Parameters

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

ApiSerializer attribute(string $name, $callback)

Parameters

string $name
$callback

Return Value

ApiSerializer

ApiSerializer attributes(callable|string $callback)

Add to or modify the attributes array of this serializer.

Parameters

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

Return Value

ApiSerializer

ApiSerializer mutate(callable|string $callback) deprecated

deprecated in beta 16, removed in beta 17

Add to or modify the attributes array of this serializer.

Parameters

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

Return Value

ApiSerializer

ApiSerializer hasOne(string $name, string $serializerClass)

Establish a simple hasOne relationship from this serializer to another serializer.

This represents a one-to-one relationship.

Parameters

string $name
string $serializerClass

Return Value

ApiSerializer

ApiSerializer hasMany(string $name, string $serializerClass)

Establish a simple hasMany relationship from this serializer to another serializer.

This represents a one-to-many relationship.

Parameters

string $name
string $serializerClass

Return Value

ApiSerializer

ApiSerializer relationship(string $name, $callback)

Add a relationship from this serializer to another serializer.

Parameters

string $name
$callback

Return Value

ApiSerializer

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

Parameters

Container $container
Extension $extension