Adding a table to a Livewire component

Typed property App\Livewire\Company\CompanyList::$user must not be accessed before initialization


I got the above error. I'm trying to show the users who belong to companies. I've no idea.

<?php

namespace App\Livewire\Company;


class CompanyList extends Component implements Forms\Contracts\HasForms, Tables\Contracts\HasTable
{
    use Forms\Concerns\InteractsWithForms;
    use Tables\Concerns\InteractsWithTable;

    public User $user;

    public function table(Table $table): Table
    {
        return $table
            ->relationship(fn (): HasMany => $this->user->companies())
            ->columns([
                Tables\Columns\ImageColumn::make('company_logo_path')
                    ->label('Company Logo'),
                Tables\Columns\TextColumn::make('name')
                    ->label(__('translations.field.company_name')),
                Tables\Columns\TextColumn::make('email')
                    ->label(__('translations.field.email')),
                Tables\Columns\TextColumn::make('location')
                    ->label(__('translations.field.location')),
            ]),
//
    }

    public function render(): View
    {
        return view('livewire.company.company-list')->layout('layouts.profile-layout');
    }
}
Was this page helpful?