tell me the easiest way to get a relationship model for query builder?

you need to use whereHas for filter data from relationship table assume you have set plan as relationship function inside Product model so you code will be like this

$results = Product::where('name', 'like', '%'. $request->input('search-product-name'). '%')
    ->whereHas("plan", function ($q) use ($request) {
        $q->where('name', 'like', '%'. $request->input('search-product-plan'). '%');

ref link

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top