Skip to content
Merged

Dev #3466

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/MediaUpload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class MediaUpload extends Model
{
protected $fillable = [
'title',
'file_path',
'disk',
];

public function getResolvedUrlAttribute(): ?string
{
if (empty($this->file_path)) {
return null;
}

return Storage::disk($this->disk ?: 'resources')->url($this->file_path);
}
}
68 changes: 68 additions & 0 deletions app/Nova/MediaUpload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\File;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;

class MediaUpload extends Resource
{
public static $group = 'Resources';

public static $model = \App\MediaUpload::class;

public static $title = 'title';

public static $search = [
'id',
'title',
'file_path',
];

public static function label()
{
return 'Uploads';
}

public static function singularLabel()
{
return 'Upload';
}

public function fields(Request $request): array
{
return [
ID::make()->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 '<a href="' . e($url) . '" target="_blank" rel="noopener noreferrer">' . e($url) . '</a>';
})
->asHtml()
->onlyOnDetail(),

Text::make('URL', function () {
return $this->resolved_url ?: '-';
})->onlyOnIndex(),
];
}
}
2 changes: 2 additions & 0 deletions app/Providers/NovaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('media_uploads', function (Blueprint $table) {
$table->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');
}
};
Loading