I am doing a filter for the search engine in a section I have: table A and table B related by 1 to n. table A -> A_id(Primary)... table B->B_id(Primary),A_id(foreing),customerId(foreing)...
I access from table A to the data in table B via the model so I'm forced to use the model and I can't use a db::table because I have all the functionality implemented and would have to redo it.
The filter for the search engine is based on looking in table B for records that match the id that I pass and they would look in the clientId column so that it returns me the info from table A
Then I use that query to search table B and return the model related to table A in such a way that if the client is in two rows of table A, it returns those rows.
$consulta=A::where('A_id', function($consulta) use($request) { $consulta->select('A_id')->from('B')->where('cliente_id', $request->cliente )->first();} )->paginate($this->numeroRegistrosPagina);
Currently this query fails if you remove first() it gives an error cardinality violation: 1242 Subquery returns more than 1 row because the subquery returns more than one row and it is normal since the clients can be in more than one row of the table A. So how can I fix this? Model B can be used since it also has the id of table A.
Thank you all
The data of model A can be obtained without problems, from model B, with the implementation of the corresponding relation method, for example;
And when you select an object from model B, you already have the data from A;