#Using $id from one table into another table

2 messages · Page 1 of 1 (latest)

opal rover
#

I want to use an $id from one table to show the results of that in another table.
The following code snippet id from my departments table form.

protected function getTableRecordUrlUsing(): ?Closure
{
  return fn (Department $record): string => route('sections', $record->id);
}

that $id is sent to my sections table, this is how I am handling it(not working, it's displaying all the sections in the different departments instead of just the one department)
here is the code,

class SectionTable extends Component implements Tables\Contracts\HasTable
{

    use Tables\Concerns\InteractsWithTable;

    public function mount($id)
    {
        $this->form->fill([
            'section_name' => Section::where('department_id',$id)->pluck('section_name')
        ]);
    }
    protected function getTableQuery(): Builder
    {
        return Section::query();
    }

    protected function getTableColumns(): array
    {
        return [
            TextColumn::make('section_name')
        ];
    }

    public function render(): View
    {
        return view('livewire.tables.section-table');
    }
}

opal rover
#

I have used

->getStateUsing(function(Section $record){
                return $record->where('department_id', $this->departmentId)->pluck('section_name');
            })

but it returns an array in the columns instead of a single value in each column