Have you tried nested relationships?
Customer::with('Inquiry.Booking', function($q) use ($searchquery){
$q->where('yourColumn', 'LIKE', "%$searchquery%");
})->get();
Ref: https://laravel.com/docs/5.5/eloquent-relationships#querying-relations
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello Community,
I created a really nice Application with the help of Laravel, but there are a few things that I couldn't solve. I hope you can help me.
Here is a simplificated Screenshot of my DB-Schema: https://imgur.com/ItUeDgN
The relations are following:
Customer:
public function inquiries() {
return $this->hasMany(Inquiry::class);
}
Inquiry:
public function booking() {
return $this->hasOne(Booking::class);
}
public function customer() {
return $this->belongsTo(Customer::class);
}
Booking:
public function inquiry() {
return $this->belongsTo(Inquiry::class);
}
My Question: How can I create a search-form that looking for Customers that have made a Booking?
Please or to participate in this conversation.