mirror of
https://github.com/flarum/framework.git
synced 2025-03-04 00:37:40 +08:00
fix: hard to track error
This commit is contained in:
parent
d09ff7176c
commit
6e5180dcfe
@ -10,9 +10,22 @@
|
||||
namespace Flarum\Api\Schema\Relationship;
|
||||
|
||||
use Flarum\Api\Schema\Concerns\FlarumRelationship;
|
||||
use InvalidArgumentException;
|
||||
use Tobyz\JsonApiServer\Context;
|
||||
use Tobyz\JsonApiServer\Laravel\Field\ToMany as BaseToMany;
|
||||
|
||||
class ToMany extends BaseToMany
|
||||
{
|
||||
use FlarumRelationship;
|
||||
|
||||
public function serializeValue($value, Context $context): mixed
|
||||
{
|
||||
if ($value && ! is_array($value) && method_exists($value, 'toArray')) {
|
||||
$value = $value->toArray();
|
||||
} elseif ($value && ! is_array($value)) {
|
||||
throw new InvalidArgumentException(sprintf('Relationship value [%s] must be an array', $this->name));
|
||||
}
|
||||
|
||||
return parent::serializeValue($value, $context);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user