Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dllister's avatar

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>]

0 likes
10 replies
devSSI's avatar

Hi, can you please try to repost code part again? :)

devSSI's avatar

@dllister can you recheck if you have any class named like this (doesn't matter if it is Livewire class or not :D anywhere in the app?)

dllister's avatar

@devSSI I did a search with the grep method looking for that class and I only have it in 2 files, the first one in the list that links the fashion. and the liveware model only there. In my liverware-components.php when I refresh I don't even get the cache with the agent relationship.

devSSI's avatar

@dllister I mean it does not make sense to throw this error if there is not somewhere in the filesystem class with this name :/

Snapey's avatar

try composer dump

So this error is purely in your editor, not an error thrown by the code?

What editor do you use?

Snapey's avatar

@dllister please mark as solved by selecting which answer helped you the most, or put your solution and select that

Please or to participate in this conversation.