Last active
January 3, 2022 11:31
-
-
Save NandoKstroNet/9795388e5dd02e6b150f147d73ae17de to your computer and use it in GitHub Desktop.
Componente Edit Vídeo - Curso Laravel Mastery em https://laravelmastery.com.br
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
<div class="max-w-7xl mx-auto mt-10 py-6 px-4 sm:px-6 lg:px-8"> | |
<x-slot name="header">Editar Vídeo</x-slot> | |
@if(session()->has('success')) | |
<div class="w-full px-2 py-4 border border-green-500 bg-green-400 text-white rounded mb-10"> | |
{{session('success')}} | |
</div> | |
@endif | |
<form action="" wire:submit.prevent="editVideo"> | |
<div class="w-full mb-5"> | |
<label class="block">Titulo</label> | |
<input type="text" wire:model.defer="video.name" class="w-full @error('video.name') border-red-700 @enderror"> | |
@error('video.name') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
<div class="mb-5"> | |
<label class="block">Descrição</label> | |
<input type="text" wire:model.defer="video.description" class="w-full @error('video.description') border-red-700 @enderror"> | |
@error('video.description') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
<div class="w-full flex justify-between mb-5"> | |
<div class="w-1/3 px-2"> | |
<label class="block">Alterar Thumb do Vídeo</label> | |
<input type="file" wire:model="thumb" class="w-full @error('thumb') border-red-700 @enderror"> | |
@error('video.description') | |
<strong class="block mt-4 text-red-700 font-bold">{{$message}}</strong> | |
@enderror | |
</div> | |
<div class="w-2/3"> | |
@if($thumb) | |
<img src="{{$thumb->temporaryUrl()}}" alt="Thumb do Vídeo {{$video->name}}" class="p-2 border border-gray-400 bg-white rounded"> | |
@else | |
<img src="{{asset('storage/' . $video->thumb)}}" alt="Thumb do Vídeo {{$video->name}}" | |
class="p-2 border border-gray-400 bg-white rounded"> | |
@endif | |
</div> | |
</div> | |
<button class="border border-green-500 bg-green-800 text-white px-5 py-2 rounded">Atualizar Vídeo</button> | |
</form> | |
</div> |
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\Content\Video; | |
use Livewire\Component; | |
use App\Models\Video; | |
use Livewire\WithFileUploads; | |
class EditVideo extends Component | |
{ | |
use WithFileUploads; | |
public Video $video; | |
public $thumb; | |
public $rules = [ | |
'video.name' => 'required', | |
'video.description' => 'nullable', | |
'thumb' => 'image|required' | |
]; | |
public function editVideo() | |
{ | |
$this->validate(); | |
if($this->thumb) { | |
$thumbnail = $this->video->code . '/thumbnail.' . $this->thumb->getClientOriginalExtension(); | |
$this->video->thumb = $this->thumb->storeAs('thumbnails', $thumbnail, 'public'); | |
} | |
$this->video->save(); | |
session()->flash('success', 'Vídeo atualizado com sucesso!'); | |
} | |
public function render() | |
{ | |
return view('livewire.content.video.edit-video'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment