Answer the question
In order to leave comments, you need to log in
How to use one query builder with different parameters?
Good afternoon. There is a large query builder, which is assembled from several queries. The same query must be used several times, but with different parameters. But I can't find a way to insert different parameters in any way.
An example is very rough:
$query = Client::join('emails', 'emails.client_id', '=', 'clients.id')
->whereIn('email', ['[email protected]', '[email protected]'])
->get();
$query = Client::join('emails', 'emails.client_id', '=', 'clients.id')
->whereIn('email', ':arr']);
foreach($cs as $c){
$res = $query->setVars(':arr' => ['[email protected]', '[email protected]'])->get()
}
Answer the question
In order to leave comments, you need to log in
There is no easy way.
You can try like this
$builder = function($params) {
return Client::join('emails', 'emails.client_id', '=', 'clients.id')->whereIn('email', $params]);
}
foreach($cs as $c){
$res = $builder(['[email protected]', '[email protected]'])->get();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question