Skip to content

Commit d386c8b

Browse files
authored
Merge pull request #3466 from codeeu/dev
Dev
2 parents 516a8cd + 8acfa8c commit d386c8b

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

app/MediaUpload.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Support\Facades\Storage;
7+
8+
class MediaUpload extends Model
9+
{
10+
protected $fillable = [
11+
'title',
12+
'file_path',
13+
'disk',
14+
];
15+
16+
public function getResolvedUrlAttribute(): ?string
17+
{
18+
if (empty($this->file_path)) {
19+
return null;
20+
}
21+
22+
return Storage::disk($this->disk ?: 'resources')->url($this->file_path);
23+
}
24+
}

app/Nova/MediaUpload.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace App\Nova;
4+
5+
use Illuminate\Http\Request;
6+
use Laravel\Nova\Fields\File;
7+
use Laravel\Nova\Fields\ID;
8+
use Laravel\Nova\Fields\Text;
9+
10+
class MediaUpload extends Resource
11+
{
12+
public static $group = 'Resources';
13+
14+
public static $model = \App\MediaUpload::class;
15+
16+
public static $title = 'title';
17+
18+
public static $search = [
19+
'id',
20+
'title',
21+
'file_path',
22+
];
23+
24+
public static function label()
25+
{
26+
return 'Uploads';
27+
}
28+
29+
public static function singularLabel()
30+
{
31+
return 'Upload';
32+
}
33+
34+
public function fields(Request $request): array
35+
{
36+
return [
37+
ID::make()->sortable(),
38+
39+
Text::make('Title')
40+
->nullable()
41+
->help('Optional label to help identify this file in Nova.'),
42+
43+
File::make('File', 'file_path')
44+
->disk('resources')
45+
->path('nova/uploads')
46+
->prunable()
47+
->creationRules('required')
48+
->rules('required', 'max:51200', 'mimes:jpg,jpeg,png,gif,webp,svg,pdf,doc,docx,ppt,pptx,xls,xlsx,txt')
49+
->help('Uploads directly to S3 disk "resources" under folder "nova/uploads".'),
50+
51+
Text::make('URL', function () {
52+
if (empty($this->resolved_url)) {
53+
return '-';
54+
}
55+
56+
$url = $this->resolved_url;
57+
58+
return '<a href="' . e($url) . '" target="_blank" rel="noopener noreferrer">' . e($url) . '</a>';
59+
})
60+
->asHtml()
61+
->onlyOnDetail(),
62+
63+
Text::make('URL', function () {
64+
return $this->resolved_url ?: '-';
65+
})->onlyOnIndex(),
66+
];
67+
}
68+
}

app/Providers/NovaServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Providers;
44

55
use App\Nova\Dashboards\Main;
6+
use App\Nova\MediaUpload as MediaUploadNova;
67
use App\Nova\Metrics\EventCount;
78
use App\Nova\Metrics\EventsPerDay;
89
use App\Nova\Metrics\ImporterTrend;
@@ -27,6 +28,7 @@ public function boot(): void
2728
// Explicitly register newly added resources to avoid sidebar discovery misses.
2829
Nova::resources([
2930
TrainingResourceNova::class,
31+
MediaUploadNova::class,
3032
]);
3133

3234
// Ensure dashboards are registered at boot so /nova/dashboards/main is always available
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('media_uploads', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('title')->nullable();
17+
$table->string('file_path');
18+
$table->string('disk')->default('resources');
19+
$table->timestamps();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
Schema::dropIfExists('media_uploads');
29+
}
30+
};

0 commit comments

Comments
 (0)