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

Randy_Johnson's avatar

Livewire Component not found

Hi, I am trying to do something here which am not sure if am going the right way about.

Component [show-admins] class not found: [App\Http\Livewire\ShowAdmins] 

ShowAdmins

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Fee;
use App\Models\Grade;
use App\Models\Injury;
use App\Models\Payment;
use App\Models\Report;
use App\Models\Subject;
use App\Models\TimeTable;
use App\Models\User;

class Admin extends Component
{
    private $x;
    private $data;
    

    private function Fee() {
        $this->data = Fee::all();
    }

    private function Grade() {
        $x = "Grades";
    }

    private function Injury() {
        $x = "Injuries";
    }

    private function Payment() {
        $x = "Payments";
    }

    private function Report() {
        $x = "Grades";
    }

    private function Subject() {
        $x = "Subjects";
    }

    private function TimeTable() {
        $x = "TimeTables";
    }

    private function User() {
        $x = "Users";
    }

    public function render()
    {
        if ($x = "Fees") {
            return view('livewire.fee');
        } else if ($x = "Grades") {
            return view('livewire.grade');
        } else if ($x = "Injuries") {
            return view('livewire.injury');
        } else if ($x = "Payments") {
            return view('livewire.payment');
        } else if ($x = "Reports") {
            return view('livewire.report');
        } else if ($x = "Subjects") {
            return view('livewire.subject');
        } else if ($x = "TimeTables") {
            return view('livewire.timetable');
        } else if ($x = "Users") {
            $data = User::all();
            return view('livewire.users')->with('data', $data);
        } else {
            $data = User::all();
            return view('livewire.users')->with('data', $data);
        }
    }
}
0 likes
3 replies
ollie_123's avatar
Level 6

Hi @randy_johnson

It looks as though you're calling show-admins but your Livewire component is called Admin.

You either need to change your Livewire component name to class ShowAdmins along with the file name or change the href & route to match your existing component.

Snapey's avatar

your component is called Admin, not ShowAdmins

Randy_Johnson's avatar

Now I am seem to be getting a problem where the if statement is ignored completely, $x is set to Users but its jumping into the first statement as if $x was set to Fees.

Its giving me this error which is strange because before trying out this new tactic in displaying each set of data individually it was working fine.

Invalid argument supplied for foreach() (View: C:\Users\Josh\Desktop\Projects\spatie-permissions\resources\views\livewire\show-fees.blade.php) (View: C:\Users\Josh\Desktop\Projects\spatie-permissions\resources\views\livewire\show-fees.blade.php) 
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Fee;
use App\Models\Grade;
use App\Models\Injury;
use App\Models\Payment;
use App\Models\Report;
use App\Models\Subject;
use App\Models\TimeTable;
use App\Models\User;

class ShowAdmins extends Component
{
    public $x = "Users";
    public $data;
    
    private function Fee() {
        $this->x = "Fees";
    }

    private function Grade() {
        $this->x = "Grades";
    }

    private function Injury() {
        $this->x = "Injuries";
    }

    private function Payment() {
        $this->x = "Payments";
    }

    private function Report() {
        $this->x = "Grades";
    }

    private function Subject() {
        $this->x = "Subjects";
    }

    private function TimeTable() {
        $this->x = "TimeTables";
    }

    private function User() {
        $this->x = "Users";
    }

    public function render()
    {
        if ($x = "Fees") {
            $data = Fee::all();
            return view('livewire.show-fees')->with('data', $data);
        } else if ($x = "Grades") {
            $data = Grade::all();
            return view('livewire.show-grades')->with('data', $data);
        } else if ($x = "Injuries") {
            $data = Injury::all();
            return view('livewire.show-injuries')->with('data', $data);
        } else if ($x = "Payments") {
            $data = Payment::all();
            return view('livewire.show-payments')->with('data', $data);
        } else if ($x = "Reports") {
            $data = Subject::all();
            return view('livewire.show-reports')->with('data', $data);
        } else if ($x = "Subjects") {
            $data = TimeTable::all();
            return view('livewire.show-subjects')->with('data', $data);
        } else if ($x = "TimeTables") {
            $data = User::all();
            return view('livewire.show-time-tables')->with('data', $data);
        } else if ($x = "Users") {
            $data = User::all();
            return view('livewire.show-users')->with('data', $data);
        } else {
            $data = User::all();
            return view('livewire.show-users')->with('data', $data);
        }
    }
}

Please or to participate in this conversation.