Querying relationship

February 26, 2021

Select the all invoice of the Customers whose first names like the given search text

$invoices = Invoice::whereHas('customer', function (Builder $query) use($request) {
                $query->where('first_name', 'like', $request->s);
            })->orderBy("created_at", "desc")->paginate(10);
            return InvoiceResource::collection($invoices);