I have come across the following requirement: I need to build a query via Eloquent that has to have one or more orWhere concatenated depending on certain vendor codes, I copy the query with which I am starting this:
$pedidos = Vta_PedidosVendedor_34::with('relUsers')->where('estado', '=', '0')->
where('OrderNumber', 'like', '%' . $this->buscar . '%')->
whereBetween('date', [$fd, $fd])->
orderBy($this->orden, $this->direccion)->
paginate(15);
I explain a little more, each user who enters the system has the ability to see the orders of other users, for example if the user '34' enters he can see his orders + those of '15', '16' and '20', Now, when the user changes, for example he enters '40', he can only see the orders of '11' and his own, whose id is '40'. This is where I'm stuck, I don't know how to make this query dynamic. In other languages (C#), what he did was build a select and through an array where he put the codes that should participate in the select, he was able to dynamically build the select. I can more or less reproduce this directly using DB::, but, there is always a but, this construction doesn't let me paginate, or at least I don't know how to do it.
Thank you very much in advance and I hope you can help me.
You can use the following function to create a dynamic query depending on what you store in the array