-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathMediaFields.php
63 lines (47 loc) · 1.86 KB
/
MediaFields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace DmitryBubyakin\NovaMedialibraryField\Fields\Support;
use App\Nova\Resource;
use DmitryBubyakin\NovaMedialibraryField\Fields\GeneratedConversions;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class MediaFields
{
public static function make(): callable
{
return function () {
/** @var Resource $this */
/** @var Media $resource */
$resource = $this->model();
$mediaUrlCallback = function () use ($resource): ?string {
return $resource->exists ? $resource->getFullUrl() : null;
};
$mediaSizeDisplayCallback = function () use ($resource): ?string {
return $resource->humanReadableSize;
};
$updatedAtDisplayCallback = function () use ($resource): ?string {
return $resource->updated_at->diffForHumans();
};
return [
ID::make(),
Text::make(__('Media Filename'), 'file_name')
->rules('required', 'min:2'),
Textarea::make(__('Media Description'), 'custom_properties->description')
->alwaysShow(),
Text::make(__('Media Disk'))
->exceptOnForms(),
Text::make(__('Media Download Url'), $mediaUrlCallback),
Text::make(__('Media Size'))
->displayUsing($mediaSizeDisplayCallback)
->exceptOnForms(),
Text::make(__('Media Updated At'))
->displayUsing($updatedAtDisplayCallback)
->exceptOnForms(),
GeneratedConversions::make(__('Media Conversions')),
];
};
}
}