Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created January 17, 2021 22:27
Show Gist options
  • Save jongravois/42fb6b1b0678f3dd023ef5c450dfff9a to your computer and use it in GitHub Desktop.
Save jongravois/42fb6b1b0678f3dd023ef5c450dfff9a to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire\Tickets;
use App\Models\Ticket;
use Livewire\Component;
use Spatie\MediaLibraryPro\Http\Livewire\Concerns\WithMedia;
class SingleTicket extends Component
{
use WithMedia;
public $ticketID;
public Ticket $ticket;
public $mediaComponentNames = ['uploads'];
public $message = '';
public $uploads = [];
protected $rules = [
'ticket.title' => 'nullable',
'uploads.*.name' => 'nullable',
];
public function mount($id)
{
$this->ticketID = $id;
$this->ticket = Ticket::firstOrCreate(['id' => $id]);
$this->uploads = $this->ticket->getMedia();
} // end function
public function render()
{
return view('livewire.tickets.single-ticket');
} // end function
public function submit()
{
$this->validate();
$this->ticket->save();
$this
->ticket
->syncFromMediaLibraryRequest($this->uploads)
->toMediaCollection('uploads');
$this->message = 'Your form has been submitted';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment