lundi 22 novembre 2021

Search Multiple ID's with Multiple Rows by Eloquent

I have one table which is used to get data combination of input data.like multiple molecule(chemical combination) as one combination.

Input

$id = $required->input('search'); // array:2 [ 0 => "3" 1 => "8"]

Case 1:

Table 1

id refid product_id name ref_2
1 1,3,46,7 5 test 6
2 1,3,8,90 10 test1 8
3 3,8,67 14 test 4 11
4 8,699, 19 test 4 11

query

$model=Model::whereIn('ref_id',$id)->pluck('product_id');

Fetch Product, query of combination contains id's 3,8

but it is fetching id's contains 3 or 8

Case 2

Table 2

id refid product_id name ref_2
1 3 5 test 6
2 5 10 test1 8
3 8 5 test 4 11
4 6 19 test 4 11
$model =MOdel::whereIn('ref_id',$id)->groupBy('product_id)->pluck('product_id');

Is this possible to do and is there a better method of doing this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire