From 2d999a6d503c0bba79da7a29fc588b27dcb8366e Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Mon, 30 Mar 2026 15:19:47 +0100 Subject: [PATCH] upload images to nova --- app/MediaUpload.php | 24 +++++++ app/Nova/MediaUpload.php | 68 +++++++++++++++++++ app/Providers/NovaServiceProvider.php | 2 + ...3_23_120000_create_media_uploads_table.php | 30 ++++++++ 4 files changed, 124 insertions(+) create mode 100644 app/MediaUpload.php create mode 100644 app/Nova/MediaUpload.php create mode 100644 database/migrations/2026_03_23_120000_create_media_uploads_table.php diff --git a/app/MediaUpload.php b/app/MediaUpload.php new file mode 100644 index 000000000..d4c68220c --- /dev/null +++ b/app/MediaUpload.php @@ -0,0 +1,24 @@ +file_path)) { + return null; + } + + return Storage::disk($this->disk ?: 'resources')->url($this->file_path); + } +} diff --git a/app/Nova/MediaUpload.php b/app/Nova/MediaUpload.php new file mode 100644 index 000000000..3cc7b83e3 --- /dev/null +++ b/app/Nova/MediaUpload.php @@ -0,0 +1,68 @@ +sortable(), + + Text::make('Title') + ->nullable() + ->help('Optional label to help identify this file in Nova.'), + + File::make('File', 'file_path') + ->disk('resources') + ->path('nova/uploads') + ->prunable() + ->creationRules('required') + ->rules('required', 'max:51200', 'mimes:jpg,jpeg,png,gif,webp,svg,pdf,doc,docx,ppt,pptx,xls,xlsx,txt') + ->help('Uploads directly to S3 disk "resources" under folder "nova/uploads".'), + + Text::make('URL', function () { + if (empty($this->resolved_url)) { + return '-'; + } + + $url = $this->resolved_url; + + return '' . e($url) . ''; + }) + ->asHtml() + ->onlyOnDetail(), + + Text::make('URL', function () { + return $this->resolved_url ?: '-'; + })->onlyOnIndex(), + ]; + } +} diff --git a/app/Providers/NovaServiceProvider.php b/app/Providers/NovaServiceProvider.php index f0931770b..babd28f34 100644 --- a/app/Providers/NovaServiceProvider.php +++ b/app/Providers/NovaServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Nova\Dashboards\Main; +use App\Nova\MediaUpload as MediaUploadNova; use App\Nova\Metrics\EventCount; use App\Nova\Metrics\EventsPerDay; use App\Nova\Metrics\ImporterTrend; @@ -27,6 +28,7 @@ public function boot(): void // Explicitly register newly added resources to avoid sidebar discovery misses. Nova::resources([ TrainingResourceNova::class, + MediaUploadNova::class, ]); // Ensure dashboards are registered at boot so /nova/dashboards/main is always available diff --git a/database/migrations/2026_03_23_120000_create_media_uploads_table.php b/database/migrations/2026_03_23_120000_create_media_uploads_table.php new file mode 100644 index 000000000..1c2d6737c --- /dev/null +++ b/database/migrations/2026_03_23_120000_create_media_uploads_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('title')->nullable(); + $table->string('file_path'); + $table->string('disk')->default('resources'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('media_uploads'); + } +};