I'm working on a Laravel/Livewire project and there is a table with these Datas: attribute, value, price I need to make an array with this data with for loop that return something like this: <pre lang="PHP"> $property=[ 'attribute1'=>['value'=>'price','value2'=>'price2','...'=>'...'], 'attribute2'=>['value'=>'price','value2'=>'price2', '...'=>'...'], '...'=>['...'=>'...'], ];
$property= [ 'size'=>['x'=>'30000','xl'=>'35000'], 'material'=>['wood'=>'55000','glass'=>'85000'] ];
I try this but it returns wrong data <pre lang="PHP"> public $product,$key,$properties; public function mount($id){ $this->product=Product::with('attr')->findOrFail($id); $db=DB::table('attr_product')->where('product_id',$id)->get()->unique('attr_id')->count(); for ($I=0; $I<$dB;$I++) { $attr_id=$this->product->attr[$i]->id; $attr=$this->product->attr[$i]->title; $value=$this->product->attr[$i]->pivot->value; $price=$this->product->attr[$i]->pivot->price; $pivotTableCount=DB::table('attr_product')->where('attr_id',$attr_id)->count(); for ($j=0;$j<$pivotTableCount;$j++){ $vp=array($value=>$price); } $this->properties[]=[$attr=>$vp]; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)