Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search on pivot table #72

Open
anzalpa opened this issue Nov 19, 2022 · 3 comments
Open

Search on pivot table #72

anzalpa opened this issue Nov 19, 2022 · 3 comments

Comments

@anzalpa
Copy link

anzalpa commented Nov 19, 2022

@pascalbaljet Is it possible to search on pivot table?

I have the following models (participant belongsToMany project),

participants
    id

participant_project 	
    participant_id
    project_id
    first_name
    last_name

projects
    id	

Getting Column not found: 1054 Unknown column 'project_participant.id' in 'field list' error when I try this; as I don't have an id column in the pivot table.

Search::new()
    ->add(\App\Order::whereIn('project_id', $projects), 'confirmation_number')
    ->add(\App\ProjectParticipant::whereIn('project_id', $projects), ['first_name', 'last_name'])
    ->orderByRelevance()
    ->beginWithWildcard()
    ->paginate(20)
    ->search($request->search);

Also, I tried using join, but not working as expected
->add(\App\Participant::join('project_participant', fn($join) => $join->on('participants.id', '=', 'project_participant.participant_id')->where('project_participant.project_id', 8)), ['project_participant.first_name', 'project_participant.last_name'])

Is there any way to achieve this?

@pascalbaljet
Copy link
Contributor

Which model do you want in the search results? Participant, Project, or do you want the ParticipantProject pivot as result?

@anzalpa
Copy link
Author

anzalpa commented Jan 9, 2023

@pascalbaljet I want to search the first_name and last_name on the pivot table(participant_project)

@ascepanovic
Copy link

@anzalpa did u mange to resolve this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants