Skip to content

How to display Many-to-Many relationship? #1161

Closed Answered by lrljoe
rhonautix asked this question in Q&A
Discussion options

You must be logged in to vote

If you want it sortable/searchable, then you'd need to use a callback in the searchable/sortable function, for example the below is a good jumping off point for you:

Column::make('Companies')
                ->label(
                    fn($row, Column $column) => view('livewire.p-o-c.poc-clients')->withRow($row)
                )
                ->searchable(
                  fn(Builder $query, $searchTerm) => $query->whereHas('clients', function (Builder $query) use ($searchTerm) {
                     $query->where('company_name', 'like', $searchTerm);
                  })
                ),

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@lrljoe
Comment options

lrljoe Apr 14, 2023
Collaborator Sponsor

Answer selected by lrljoe
Comment options

You must be logged in to vote
1 reply
@lrljoe
Comment options

lrljoe Aug 30, 2024
Collaborator Sponsor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants