How to display attached file

Hi, I have an edit class for my model named Post. How do I display the attached file that exists on the database? The file was uploaded using the Spatie Media Library plugin for filamentPHP This is my livewire class Edit.php. <?php namespace App\Http\Livewire\Posts; class Edit extends Component implements Forms\Contracts\HasForms { use Forms\Concerns\InteractsWithForms; public Post $post; public $descripton; public function mount(): void {
$this->form->fill([ 'description' => $this -> post -> description, 'attachment' => $this -> post -> getMedia('post-attachments') ]); } Only the property description was pulled from database and displayed on the edit form
3 Replies
Dennis Koch
Dennis Koch2y ago
It should just work. Any Console errors?
Sugbo
SugboOP2y ago
Hi bro. Appreciate the response. There is no console error. The $this -> post -> getMedia('post-attachments') returns a collection, I am thinking maybe I should do a loop or something? Totally confused But I am like how do I loop it in the mount method
Dennis Koch
Dennis Koch2y ago
And you only a single attachment? Then you definitely should pluck the first one. Like in any other method 🤷‍♂️
Want results from more Discord servers?
Add your server