feat: Upload de imagem na edição de clientes/Exibição de imagem do cliente.
feat: Upload de imagem na edição de clientes/Exibição de imagem do cliente.
This commit is contained in:
commit
576e4cfe57
|
|
@ -5,12 +5,16 @@
|
|||
use App\Livewire\Forms\ClientForm;
|
||||
use App\Models\Client;
|
||||
use App\Services\ClientService;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
use Exception;
|
||||
|
||||
class EditClient extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Client $client;
|
||||
public ClientForm $clientForm;
|
||||
|
|
@ -35,6 +39,14 @@ public function edit(ClientService $clientService)
|
|||
{
|
||||
$data = $this->clientForm->validate();
|
||||
|
||||
if ($this->clientForm->profile_image_path) {
|
||||
$path = $this->clientForm->profile_image_path->store('client_logos', 'public');
|
||||
$data['profile_image_path'] = $path;
|
||||
}
|
||||
|
||||
$data['root_password'] = Crypt::encryptString($data['root_password']);
|
||||
|
||||
|
||||
try {
|
||||
if (!$clientService->updateClient($this->client, $data)) {
|
||||
throw new Exception('O serviço não confirmou a atualização.');
|
||||
|
|
|
|||
|
|
@ -5,11 +5,15 @@
|
|||
use App\Models\User;
|
||||
use App\Services\UserService;
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
class ShowUsers extends Component
|
||||
{
|
||||
public $users = [];
|
||||
|
||||
#[On('user-updated')]
|
||||
#[On('user-created')]
|
||||
|
||||
public function mount(UserService $userService)
|
||||
{
|
||||
$this->users = $userService->showUsers();
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public function editUser(UserService $userService)
|
|||
}
|
||||
|
||||
$this->dispatch('user-updated');
|
||||
$this->dispatch('notify', message: $this->clientForm->client_name . ' atualizado com sucesso!');
|
||||
$this->dispatch('notify', message: $this->userForm->name . ' atualizado com sucesso!');
|
||||
} catch (\Exception $e) {
|
||||
$this->dispatch('notify', message: 'Falha na edição: ' . $e->getMessage(), type: 'error');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<div class="client-card">
|
||||
<div class="client-card-header">
|
||||
<div class="client-avatar">
|
||||
<img src="{{ Vite::asset('resources/images/mr-distribuidora.svg') }}" alt="Avatar do Cliente"
|
||||
<img src="{{ asset('storage/' . $client->profile_image_path) }}" alt="Avatar do Cliente"
|
||||
class="w-32 h-32 rounded-full object-cover">
|
||||
</div>
|
||||
<div x-data="{ open: false }" @click.outside="open = false" class="client-options-menu">
|
||||
|
|
@ -16,11 +16,17 @@ class="w-32 h-32 rounded-full object-cover">
|
|||
</button>
|
||||
|
||||
<ul x-show="open" class="client-options-list" x-transition>
|
||||
<li><a href="#" class="client-option-item" x-on:click.prevent="$dispatch('view-client', { id: '{{ $client->id }}' })">Ver Detalhes</a></li>
|
||||
<li><a href=" #" class="client-option-item" x-on:click.prevent="$dispatch('update-client', { id: '{{ $client->id }}' })">Editar Cliente</a></li>
|
||||
<li><a href="#" class="client-option-item text-red-600" x-on:click.prevent="$dispatch('sure', { id: '{{ $client->id }}' })"> Excluir Cliente</a></li>
|
||||
<li><a href="#" class="client-option-item"
|
||||
x-on:click.prevent="$dispatch('view-client', { id: '{{ $client->id }}' })">Ver Detalhes</a>
|
||||
</li>
|
||||
<li><a href=" #" class="client-option-item"
|
||||
x-on:click.prevent="$dispatch('update-client', { id: '{{ $client->id }}' })">Editar
|
||||
Cliente</a></li>
|
||||
<li><a href="#" class="client-option-item text-red-600"
|
||||
x-on:click.prevent="$dispatch('sure', { id: '{{ $client->id }}' })"> Excluir Cliente</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="client-card-name">
|
||||
|
|
|
|||
Loading…
Reference in New Issue