Add support uuid for attachments
Overriding the Attachment and Attachmentable models is not a problem — Dashboard::useModel handles that.
The problem lies in the attachment-related UI components that do not support UUIDs: Attach, Upload, Picture, and Cropper (which extends Picture).
For Attach in the loadRelatedAttachments method, and for Upload in the __construct method, the original code is:
if (! Assert::isIntArray($value)) {
return $this;
}
I override it with:
if (! Assert::isArrayClosure($value, static fn (string $uuid) => \Ramsey\Uuid\Uuid::isValid($uuid))) {
return $this;
}
For Picture, in the targetId method, the original code is:
if (! ctype_digit($value)) {
return;
}
I override it with:
if (\Ramsey\Uuid\Uuid::isValid($value)) {
return;
}
I understand that with these overrides the components will now support only UUIDs.
I assume that the proper long-term solution would be to add, for each component, a separate method such as targetUuid() for assigning the attribute. Or by getKeyType method from Attachment model.
For Upload and Attachment, we could add a target attribute with a default value of id. Based on the value of this target attribute, the component would validate the array of identifiers accordingly.
If this is something the platform is interested in, please provide recommendations and I will prepare a PR.
Thank you!
I definitely would like to see support for UUIDs and other identifier generation methods like nanoid.
Regarding the loadRelatedAttachments method, I see it as a fallback mechanism — something to rely on when the user hasn’t set up the relationship in advance or hasn’t prepared the data as models and instead passes only an id.
It would be great to move all validations to the model level. That would make it easier for us to adjust things later, especially since the model is exactly where we can determine in advance whether a value is auto-incremented.
I'm not sure we actually need all those UUID or numeric type checks. It seems sufficient to verify that the values aren’t objects, and if they're not, we can simply try to load them into Eloquent.