Created
January 17, 2021 22:27
-
-
Save jongravois/42fb6b1b0678f3dd023ef5c450dfff9a to your computer and use it in GitHub Desktop.
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\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