ekrbodo
RichEditor S3 private visibility
If you are building a public facing solution, like a CMS or a website, a public bucket is the right chocie. If you are building a SaaS application, where you won´t allow files to be public available or need strict security, you need a private bucket. The temporary signed URL is a security measure
11 replies
RichEditor S3 private visibility
If you have a private bucket, the uploaded documents are only reachable using the AWS keys to generate short lived signed URLs. So you if you are going to store public attachments, you need to create a public AWS bucket.
11 replies
RichEditor S3 private visibility
I ended up with creating an accessor which uses preg_replace to update the link. Kinda hacky, but works,
class UpdateSignedUrl
{
public static function update($content): array|string|null
{
$pattern_img = '/<img src="([^"]+)"/';
$pattern_a = '/<a href="(https:\/\/myawsbucket[^"]+)"/';
$pattern_text = '/(https:\/\/myawsbucket[^"]+)/';
$content = preg_replace_callback($pattern_img, function ($matches) {
$url = $matches[1];
$path = parse_url($url)['path'];
$signedUrl = static::generateSignedUrl($path);
return '<img src="' . $signedUrl . '"';
}, $content);
$content = preg_replace_callback($pattern_text, function ($matches) {
$url = $matches[1];
$path = parse_url($url)['path'];
$signedUrl = static::generateSignedUrl($path);
return $signedUrl;
}, $content);
return preg_replace_callback($pattern_a, function ($matches) {
$url = $matches[1];
$pathInfo = parse_url($url);
$path = $pathInfo['path'];
$signedUrl = static::generateSignedUrl($path);
return '<a href="' . $signedUrl . '"';
}, $content);
}
protected static function generateSignedUrl(string $path): string
{
return Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(5));
}
}
//model
protected function body(): Attribute {
return Attribute::make(
get: fn (?string $value) => UpdateSignedUrl::update($value),
);
}
If the signed linkes is stored within a repeater / builder, im using a formatStateUsing to update the signed urls:
->formatStateUsing(function ($state) { return UpdateSignedUrl::update($state); })
11 replies
Struggling with pluck
I got it working using this code:
Forms\Components\Select::make('customer_id')
->label('Tilknyttet kunde')
->default(fn ($record) => $record->id)
->options((fn (Customer $record) => Customer::where('id', $record->id)->pluck('name', 'id')))
->searchable()
->getSearchResultsUsing(fn (string $search): array => Customer::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelUsing(fn ($value): ?string => Customer::find($value)?->name),
])
5 replies
Struggling with pluck
That makes sense. I´m trying insert the selected row record as a option and default value in a select component, so basically what i need is a pluck metod on the row record
Forms\Components\Select::make('customer_id')
->label('Tilknyttet kunde')
->default(1)
->options(fn ($record) => $record->name)
])
5 replies