Created
June 2, 2021 05:40
-
-
Save robzlabz/9b463cf266b25dc52731346d24abb7d0 to your computer and use it in GitHub Desktop.
Spatie Media Library with Livewire Trait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
trait LivewireMedia | |
{ | |
public function addMediaTo($media, $collectionName) | |
{ | |
$this->addMedia($media->getRealPath()) | |
->usingName(pathinfo($media->getClientOriginalName(), PATHINFO_BASENAME)) | |
->usingFileName($media->getClientOriginalName()) | |
->toMediaCollection($collectionName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment