belongsTo(User::class); } public function links() { $result = [ 'open' => asset("/api/assets/{$this->uuid}"), 'download' => asset("/api/assets/{$this->uuid}/download"), 'direct' => asset("storage/{$this->path}") ]; if ($this->type == 'image') { $result['full'] = asset("/api/assets/{$this->uuid}/render"); $result['thumb'] = asset("/api/assets/{$this->uuid}/render?width=300"); } return $result; } public function coordinates() { return [ 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'accuracy' => $this->accuracy ]; } public function output() { return [ 'id' => $this->uuid, 'type' => $this->type, 'mime' => $this->mime, 'filename' => $this->filename, 'extension' => $this->extension, 'links' => $this->links(), 'user' => $this->user->output(), 'coordinates' => $this->coordinates(), 'created_at' => $this->created_at->toIso8601String(), 'created_by' => $this->user->name, ]; } public function saveValue($fieldName, $object) { $field = Field::byUuidOrName($fieldName)->first(); $relationValue = RelationValue::create(); $relationValue->set($this); $relationValue->update([ 'field_id' => $field->id, 'object_id' => $object->id, ]); } }