fix: hard to track error

This commit is contained in:
Sami Mazouz 2024-10-25 14:39:29 +01:00
parent d09ff7176c
commit 6e5180dcfe
No known key found for this signature in database

View File

@ -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);
}
}