Add icon to file
This commit is contained in:
parent
0c10472e2e
commit
61ed6e0a3d
|
@ -1 +1,3 @@
|
|||
/vendor/
|
||||
/.php-cs-fixer.cache
|
||||
/.phpunit.result.cache
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Zoomyboy\MedialibraryHelper;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
@ -48,6 +49,15 @@ class MediaData extends Data
|
|||
]);
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
$mime = Str::slug($this->mimeType);
|
||||
|
||||
return [
|
||||
'icon' => Storage::disk('public')->url("filetypes/{$mime}.svg"),
|
||||
];
|
||||
}
|
||||
|
||||
public static function defaultFromCollection(HasMedia $parent, MediaCollection $collection): ?self
|
||||
{
|
||||
$default = $collection->runCallback('withFallback', $parent);
|
||||
|
|
|
@ -16,6 +16,7 @@ test('it gets all medias', function () {
|
|||
$response->assertJsonPath('0.id', $firstMedia->id);
|
||||
$response->assertJsonPath('1.id', $secondMedia->id);
|
||||
$response->assertJsonPath('1.properties.test', 'old');
|
||||
$response->assertJsonPath('1.icon', url('storage/filetypes/applicationpdf.svg'));
|
||||
});
|
||||
|
||||
test('it gets media for single', function () {
|
||||
|
|
Loading…
Reference in New Issue