© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
Shaung Bhone

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');
    }
}
<?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');
    }
}
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Adding table to Livewire Component
FilamentFFilament / ❓┊help
3y ago
Adding a table to a Livewire component
FilamentFFilament / ❓┊help
2y ago
Adding tabs to a table on a custom livewire component
FilamentFFilament / ❓┊help
11mo ago
Adding a form to a Livewire component
FilamentFFilament / ❓┊help
12mo ago