I have a query which fetches one table and then the results of that query gets passed though another query.
Then I want to return all the values of that column in each row from that query.
This fetches all of the Product id's with a particular brand ID
// Fetch the Product List
$brandID = 1;
$prodList = Products::whereBrandId($brandID);
// Fetch the catalog ID of the Product
$fetchID = $prodList->lists('id');
Then print_r($fetchID) returns the array.
Array ( [0] => 10011 [1] => 10012 [2] => 10013 [3] => 10014 [4] => 10015 [5] => 10016 [6] => 10017 [7] => 10018 [8] => 10019 [9] => 10020 [10] => 10021 [11] => 10022 [12] => 10023 [13] => 10024 [14] => 10025 [15] => 10026 [16] => 10027 [17] => 10028 [18] => 10029 [19] => 10030 [20] => 10031 [21] => 10032 [22] => 10033 [23] => 10034 [24] => 10035 [25] => 10036 [26] => 10037 [27] => 10038 [28] => 10039 [29] => 10040 [30] => 10041 [31] => 10042 [32] => 10043 [33] => 10044 [34] => 10045 [35] => 10046 [36] => 10047 [37] => 10048 [38] => 10049 [39] => 10050 [40] => 10051 [41] => 10052 [42] => 10053 [43] => 10054 [44] => 10055 [45] => 10056 [46] => 10057 [47] => 10058 [48] => 10059 [49] => 10060 [50] => 10061 [51] => 10062 [52] => 10063 [53] => 10064 [54] => 10065 [55] => 10066 [56] => 10067 [57] => 10068 [58] => 10069 [59] => 10070 [60] => 10071 [61] => 10072 [62] => 10073 [63] => 10074 [64] => 10075 [65] => 10076 [66] => 10077 [67] => 10078 [68] => 10079 [69] => 10080 [70] => 10092 [71] => 10093 [72] => 10128 )
I then have a table with the fields product_id and category_id, so I want to pass the results of $fetchID though and return all values from the category_id using lists()
// Fetch the category_id where is a product_id
$catRelation = Db::table('purple_catalog_prods_cats')->whereProductId($fetchID);
$catRelList = $catRelation->lists('category_id');
This returns as empty in print_r
Finally I want to query the categories table which has id and name, and return everything. So I try to pass the $catRelList through. This doesn't work because in the previous query it returns as empty.
// Fetch the Cat list
$catList = categoryName::whereId($catRelList)->orderBy('id', 'asc');
$this->categoryName = $catList->get();
So my issue is passing though $fetchID to return all rows matching the multiple Product ID's. As when I manually enter a product ID it returns that category fine. Query Below
$catRelation = Db::table('purple_catalog_prods_cats')->whereProductId('10011');
Now where the 10011 is, I somehow want to pass multiple values through, like in the $fetchID array.
Is this possible to do and is there a better method of doing this?