Feb 1, 2018
0
Level 1
Fetch record according to attribute id
i have three tables Attribute , Attribute-values and item-Attribute-value Attribute : id , title Attribute-values : id ,title, attribute_id Item-attribute-value : id , attribute_value_id , item_id,
one item have multiple attributes so i want to fetch data according to attribute id if item contain only one attribute then return one array with all selected attribute values and if item contain multiple attribute then return multiple array and each array contain their selected values.
return DB::table('item-attribute-values')
->where('item_id',$item_id)
->join('attribute_values','attribute_values.id','=','item-attribute-values.value_id')
->join('attributes','attributes.id','=','attribute_values.attribute_id')
->select('attributes.title as attribute_name','attribute_values.title as attribute_value_name','item-attribute-values.price')
->groupBy('attributes.id')
->get();
this array return only one value of each attribute
Please or to participate in this conversation.