Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mathishuettl's avatar

Problems with search Form

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?

0 likes
3 replies
mathishuettl's avatar

@tisuchi Thanks man!!

This is my solution:

if ($request->filled("lastname")) {
                $queryBuilder->whereHas("inquiry", function($q) use ($request) {
                    $q->whereHas("customer", function($qq) use ($request)  {
                        $qq->where("lastname", "LIKE", "%" . $request->input("lastname") . "%");
                    });
                });
            }
tisuchi's avatar

Is that performing well? As long as its working, that should be fine.

Please or to participate in this conversation.