feat(events): support event cover attachments
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Domains\Ticketing\Event\Models;
|
|||||||
|
|
||||||
use App\Domains\Core\Tenant\Models\SocialMedia;
|
use App\Domains\Core\Tenant\Models\SocialMedia;
|
||||||
use App\Domains\Core\Tenant\Models\Tenant;
|
use App\Domains\Core\Tenant\Models\Tenant;
|
||||||
|
use App\Shared\Attachable\Models\Attachment;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
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;
|
||||||
@@ -11,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
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
|
class Event extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
@@ -27,6 +28,12 @@ class Event extends Model
|
|||||||
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return BelongsTo<Attachment, $this> */
|
||||||
|
public function attachment(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Attachment::class);
|
||||||
|
}
|
||||||
|
|
||||||
/** @return HasMany<EventDate, $this> */
|
/** @return HasMany<EventDate, $this> */
|
||||||
public function dates(): HasMany
|
public function dates(): HasMany
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class UpdateEventRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'title' => ['required', 'string', 'max:255'],
|
'title' => ['required', 'string', 'max:255'],
|
||||||
'location' => ['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' => ['sometimes', 'array'],
|
||||||
'social_media.*' => ['required', 'array:code,url,orden'],
|
'social_media.*' => ['required', 'array:code,url,orden'],
|
||||||
'social_media.*.code' => [
|
'social_media.*.code' => [
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class EventResource extends JsonResource
|
|||||||
'location' => $this->location,
|
'location' => $this->location,
|
||||||
'date_text' => $this->date_text,
|
'date_text' => $this->date_text,
|
||||||
'published_at' => $this->published_at?->toIso8601String(),
|
'published_at' => $this->published_at?->toIso8601String(),
|
||||||
|
'attachment_id' => $this->attachment_id,
|
||||||
'allow_ticket_refund' => $this->tenant->allow_ticket_refund,
|
'allow_ticket_refund' => $this->tenant->allow_ticket_refund,
|
||||||
'allow_ticket_total_refund' => $this->tenant->allow_ticket_total_refund,
|
'allow_ticket_total_refund' => $this->tenant->allow_ticket_total_refund,
|
||||||
'allow_ticket_partial_refund' => $this->tenant->allow_ticket_partial_refund,
|
'allow_ticket_partial_refund' => $this->tenant->allow_ticket_partial_refund,
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class EventService
|
|||||||
$event->update([
|
$event->update([
|
||||||
'title' => $data['title'],
|
'title' => $data['title'],
|
||||||
'location' => $data['location'],
|
'location' => $data['location'],
|
||||||
|
...array_intersect_key($data, ['attachment_id' => true]),
|
||||||
]);
|
]);
|
||||||
$tenant->update([
|
$tenant->update([
|
||||||
...array_intersect_key($data, array_flip([
|
...array_intersect_key($data, array_flip([
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('events', function (Blueprint $table): void {
|
||||||
|
$table->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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user