feat(attachments): add 'key' field to Attachment model and migration, generate UUID on creation
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
#[Fillable([
|
#[Fillable([
|
||||||
'attachable_type',
|
'attachable_type',
|
||||||
@@ -23,6 +24,13 @@ class Attachment extends Model
|
|||||||
|
|
||||||
protected $table = 'attachments';
|
protected $table = 'attachments';
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $attachment): void {
|
||||||
|
$attachment->key = (string) Str::uuid();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class S3TestService
|
|||||||
return [
|
return [
|
||||||
'disk' => 's3',
|
'disk' => 's3',
|
||||||
'directory' => $directory,
|
'directory' => $directory,
|
||||||
|
'key' => $path,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'filename' => basename($path),
|
'filename' => basename($path),
|
||||||
'original_name' => $file->getClientOriginalName(),
|
'original_name' => $file->getClientOriginalName(),
|
||||||
@@ -55,6 +56,7 @@ class S3TestService
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'disk' => 's3',
|
'disk' => 's3',
|
||||||
|
'key' => $path,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'temporary_url' => $this->temporaryUrlForPath($path, $expiresInMinutes),
|
'temporary_url' => $this->temporaryUrlForPath($path, $expiresInMinutes),
|
||||||
'temporary_url_expires_at' => now()->addMinutes($expiresInMinutes)->toIso8601String(),
|
'temporary_url_expires_at' => now()->addMinutes($expiresInMinutes)->toIso8601String(),
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ return new class extends Migration
|
|||||||
$table->id();
|
$table->id();
|
||||||
$table->string('attachable_type');
|
$table->string('attachable_type');
|
||||||
$table->unsignedBigInteger('attachable_id');
|
$table->unsignedBigInteger('attachable_id');
|
||||||
|
$table->uuid('key')->unique();
|
||||||
$table->string('path');
|
$table->string('path');
|
||||||
$table->string('filename');
|
$table->string('filename');
|
||||||
$table->string('type')->nullable();
|
$table->string('type')->nullable();
|
||||||
|
|||||||
Reference in New Issue
Block a user