From 8d2250d24765433416f597d6d4d571421fed264d Mon Sep 17 00:00:00 2001 From: ncoronel Date: Fri, 18 Sep 2026 14:33:21 -0300 Subject: [PATCH] feat(events): support event cover attachments --- app/Domains/Ticketing/Event/Models/Event.php | 9 ++++++- .../Event/Requests/UpdateEventRequest.php | 1 + .../Event/Resources/EventResource.php | 1 + .../Ticketing/Event/Services/EventService.php | 1 + ..._18_000900_add_attachment_id_to_events.php | 26 +++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2026_09_18_000900_add_attachment_id_to_events.php diff --git a/app/Domains/Ticketing/Event/Models/Event.php b/app/Domains/Ticketing/Event/Models/Event.php index 929019f..b792d9a 100644 --- a/app/Domains/Ticketing/Event/Models/Event.php +++ b/app/Domains/Ticketing/Event/Models/Event.php @@ -4,6 +4,7 @@ namespace App\Domains\Ticketing\Event\Models; use App\Domains\Core\Tenant\Models\SocialMedia; use App\Domains\Core\Tenant\Models\Tenant; +use App\Shared\Attachable\Models\Attachment; use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -11,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; -#[Fillable(['tenant_code', 'title', 'subtitle', 'description', 'location', 'date_text', 'published_at'])] +#[Fillable(['tenant_code', 'title', 'subtitle', 'description', 'location', 'date_text', 'published_at', 'attachment_id'])] class Event extends Model { use HasFactory; @@ -27,6 +28,12 @@ class Event extends Model return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo'); } + /** @return BelongsTo */ + public function attachment(): BelongsTo + { + return $this->belongsTo(Attachment::class); + } + /** @return HasMany */ public function dates(): HasMany { diff --git a/app/Domains/Ticketing/Event/Requests/UpdateEventRequest.php b/app/Domains/Ticketing/Event/Requests/UpdateEventRequest.php index 148eb10..d1a476b 100644 --- a/app/Domains/Ticketing/Event/Requests/UpdateEventRequest.php +++ b/app/Domains/Ticketing/Event/Requests/UpdateEventRequest.php @@ -19,6 +19,7 @@ class UpdateEventRequest extends FormRequest return [ 'title' => ['required', 'string', 'max:255'], 'location' => ['required', 'string', 'max:255'], + 'attachment_id' => ['sometimes', 'nullable', 'integer', Rule::exists('attachments', 'id')->where('type', 'image')], 'social_media' => ['sometimes', 'array'], 'social_media.*' => ['required', 'array:code,url,orden'], 'social_media.*.code' => [ diff --git a/app/Domains/Ticketing/Event/Resources/EventResource.php b/app/Domains/Ticketing/Event/Resources/EventResource.php index 11764c3..4f2ca77 100644 --- a/app/Domains/Ticketing/Event/Resources/EventResource.php +++ b/app/Domains/Ticketing/Event/Resources/EventResource.php @@ -23,6 +23,7 @@ class EventResource extends JsonResource 'location' => $this->location, 'date_text' => $this->date_text, 'published_at' => $this->published_at?->toIso8601String(), + 'attachment_id' => $this->attachment_id, 'allow_ticket_refund' => $this->tenant->allow_ticket_refund, 'allow_ticket_total_refund' => $this->tenant->allow_ticket_total_refund, 'allow_ticket_partial_refund' => $this->tenant->allow_ticket_partial_refund, diff --git a/app/Domains/Ticketing/Event/Services/EventService.php b/app/Domains/Ticketing/Event/Services/EventService.php index 0a091fa..6633154 100644 --- a/app/Domains/Ticketing/Event/Services/EventService.php +++ b/app/Domains/Ticketing/Event/Services/EventService.php @@ -47,6 +47,7 @@ class EventService $event->update([ 'title' => $data['title'], 'location' => $data['location'], + ...array_intersect_key($data, ['attachment_id' => true]), ]); $tenant->update([ ...array_intersect_key($data, array_flip([ diff --git a/database/migrations/2026_09_18_000900_add_attachment_id_to_events.php b/database/migrations/2026_09_18_000900_add_attachment_id_to_events.php new file mode 100644 index 0000000..f53b962 --- /dev/null +++ b/database/migrations/2026_09_18_000900_add_attachment_id_to_events.php @@ -0,0 +1,26 @@ +foreignId('attachment_id')->nullable()->constrained('attachments')->nullOnDelete(); + }); + } + + public function down(): void + { + Schema::table('events', function (Blueprint $table): void { + if (Schema::getConnection()->getDriverName() !== 'sqlite') { + $table->dropForeign(['attachment_id']); + } + + $table->dropColumn('attachment_id'); + }); + } +};