Currently in Image.php
I have this method:
public function getS3Paths()
{
$this->s3Path = Storage::disk('s3')->temporaryUrl($this->path, now()->addHour());
}
and everytime I need the paths I do something like this:
public function getPhotos(Request $request)
{
$photos = Image::restricted()->latest()->get();
foreach ($photos as $photo) {
$photo->getS3Paths();
}
return $photos;
}
I would like to have an accessor in Image.php
public function getS3PathAttribute()
{
return Storage::disk('s3')->temporaryUrl($this->path, now()->addHour());
}
that would be only called, if I use request similar to $photos = Image::with('s3Path')->restricted()->latest()->get();
.
Of course with()
is for Eloquent and the method would need to be named differently, but it describes my desire well. Is there some solution similar to this, where I would not need to loop the photos? Since s3, is of course paid service, which I don't need everytime I make a request for Photos.