Skip to content

Commit

Permalink
Added entity photos to api response.
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-maddock committed Jan 4, 2025
1 parent c7264f0 commit d2df521
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/Http/Resources/EntityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public function toArray($request)
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at
'updated_at' => $this->updated_at,
'primary_photo' => $this->getPrimaryPhotoPath(),
'primary_photo_thumbnail' => $this->getPrimaryPhotoThumbnailPath(),
];
}
}
25 changes: 25 additions & 0 deletions app/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Auth;
use Str;
use Storage;

/**
* App\Models\Entity.
Expand Down Expand Up @@ -530,6 +531,30 @@ public function getPrimaryPhoto(): ?Photo
return $primary;
}

// returns the actual path to the primary photo
public function getPrimaryPhotoPath(): ?string
{
$photo = $this->getPrimaryPhoto();

if ($photo) {
return Storage::disk('external')->url($photo->getStoragePath());
}

return null;
}

// returns the actual path to the thumbnail
public function getPrimaryPhotoThumbnailPath(): ?string
{
$photo = $this->getPrimaryPhoto();

if ($photo) {
return Storage::disk('external')->url($photo->getStorageThumbnail());
}

return null;
}

/**
* Return the primary location for this entity.
*
Expand Down

0 comments on commit d2df521

Please sign in to comment.