Hi, can you please try to repost code part again? :)
Cannot declare class App\Http\Livewire\Agente\AddAgenteComponent, because the name is already in use
I'm having trouble with this, and I'm sure I don't have this line repeated anywhere else, but it keeps telling me that it's already in use.
I will share part of my code. this is my liveware Model [<?php namespace App\Http\Livewire\Agente;
use App\Models\Agente; use Livewire\Component; use Livewire\WithFileUploads; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\DB;
class AddAgenteComponent extends Component \this is where it tells me that it is already in use. { use WithFileUploads;
public $id;
public $name;
public $full_name;
public $email;
public $phone;
public $agente_photo;
public $saved_agente_photo;
public $edit_mode = false;
protected $rules = [
'name' => 'required|string',
'full_name' => 'required|string',
'email' => 'nullable|email',
'phone' => 'required|string',
'agente_photo' => 'nullable|sometimes|image|max:1024',
];
protected $listeners = [
'delete_agente' => 'deleteAgente',
'update_agente' => 'updateAgente',
];
public function render()
{
return view('livewire.agente.add-agente-modal');
}
public function submit()
{
$this->validate();
DB::transaction(function () {
$data = [
'name' => $this->name,
'full_name' => $this->full_name,
'email' => $this->email,
'phone' => $this->phone,
];
if ($this->agente_photo) {
$data['agente_photo_path'] = $this->agente_photo->store('avatars', 'public');
}
$data['password'] = $this->password ? Hash::make($this->password) : null;
$agente = $this->id ? Agente::find($this->id) : new Agente();
$agente->fill($data);
$agente->save();
// Resto de la lógica...
$this->emit('success', $this->id ? __('Agente updated') : __('New agente created'));
});
$this->reset();
}
public function deleteAgente($id)
{
if ($id == Auth::id()) {
$this->emit('error', 'Agente cannot be deleted');
return;
}
Agente::destroy($id);
$this->emit('success', 'Agente successfully deleted');
}
public function updateAgente($id)
{
$this->edit_mode = true;
$agente = Agente::find($id);
if (!$agente) {
// Manejar el caso en el que el agente no se encuentra
// Puedes lanzar una excepción, redirigir, o realizar otra lógica según tu aplicación
}
$this->id = $agente->id;
$this->name = $agente->name;
$this->full_name = $agente->full_name;
$this->email = $agente->email;
$this->phone = $agente->phone;
$this->saved_agente_photo = $agente->agente_photo_path;
}
public function hydrate()
{
$this->resetErrorBag();
$this->resetValidation();
}
}]
This is how the modal was called from my blade. [livewire:agente.add-agente-modal</livewire:agente.add-agente-modal>]
Please or to participate in this conversation.