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
$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
It should just work. Any Console errors?
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
And you only a single attachment? Then you definitely should pluck the first one.
Like in any other method 🤷♂️