Hi,
how does your database look like? In general you can use something like the following in your Controller: $results = NameOfYourModel::all()->where('question_id', 'id_youSearchFor')->get(); return view('nameOfYourView',[ 'results' => $results ]);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have two different roles in my application, Applicants and Agencies. Applicants submit a form (30 questions, all radio buttons) and their answers get saved to the database with question_id, user_id and answer unless they answer "not applicable". Agencies can then use the same form to find people that match the same answers. Something like question_id = 2 and answer = Yes, question_id = 5 and answer = no, and so on, if they choose "not applicable" the question_id removed from query array ( question_id => answer, question_id => answer).
I've searched high and low and for the life of me cannot figure out how to write a query that can return user_id's from the answers table that will match query array.
Example Query array:
array = [
1 => "Yes"
2 => "Yes"
15 => "Bachelors Degree"
19 => "Air Force"
30 => "Yes"
]
So the query would need to return user_ids where question_id=1 and answer=Yes, question_id=2 and answer=Yes, question_id=15 and answer=Bachelors Degree and so on. Applicant could have more answers saved but each would have to meet this criteria first.
I have a hasMany() relationship working but can't figure out how to match the criteria and return the user.
Thanks in advance for your help.
Please or to participate in this conversation.