I don't understand your English.
I hope the question is "How", not "Who".
This looks like EAV (Entity.Attribute-Value) to me. Magento uses this approach.
You can store a value in the pivot table like this
$field = ProductGroupField::first();
$value = 'value';
$product = Product::first();
$product->productProductGroupField()->attach(array($field->id => $value));
Use attach for Many-to-Many relationship
Thank you. I was looking for the same answer. My English is poor, sorry.
Jeffrey Way, Pivot Table method I use to connect the two tables.
"php artisan generate:pivot products product_fields"
How can I add a field to pivot Table ?
I will make it easier with brackets.
I read somewhere that ((the Pivot table method you mention) sometimes makes problems).
You must (add a column to the table). (Take a look at (your migration which creates the pivot table)) to see if ((the wanted column) is created). (You can see (the definition of you table)) using phpmyadmin.
(You need to (declare that (the pivot table contains additional data))) inside the relationship, for example:
class Category
public function products(){
return $this->belongsToMany('Product')->withPivot('info');
}
Rad more here
Tanks To Firtzberg :)
im find all field in the one group : public function getGroups() { $id = Input::get('id'); $group = Productgroup::find($id); if($group) { if(count($group->productfields) >= 1) { foreach ($group->productfields as $field){
echo '
<div id="showfields" class="col-lg-12 form-group field">
<label for="product_gid" class="col-sm-2">'.$field->fieldname.' : </label>
<div class="col-sm-10">
<input type="text" name="productfield['.$field->id.']" id='.$field->id.' class="form form-control" placeholder='.$field->fieldname.' />
</div>
</div>
';
}
}
else
{
echo '
<div id="showfields" class="col-lg-12 form-group field">
<label for="product_gid" class="col-sm-2">فیلد های محصول </label>
<div class="col-sm-10">
Field Not Found .
</div>
</div>
';
}
}
else
{
return 'Group Not Found .';
}
}
The output of my fields is as follows:
array(1) { [0]=> array(5) { [26]=> string(6) "512 MB" [27]=> string(9) "4400 Mghz" [28]=> string(0) "" [29]=> string(6) "512 GB" [30]=> string(5) "12 GB" } }
How do I save it in the same table( product_productfield ) ?
My Product Model :
class Product extends \Eloquent { public function productfields() { return $this->belongsToMany('Productfield')->withPivot('value'); } }
class Productfield extends \Eloquent { public function products() { return $this->belongsToMany('Product')->withPivot('value'); } }
Fields of product_productfield : product_id | productfield_id | value
please help me for insert a record to product_productfield and set value filed !?
i understand via sync or Attach method :
$user->pivot_relationship()->attach(1, array('value' => 'abc'));
// or
$user->pivot_relationship()->sync(array(1 => array('value' => 'abc')));
I can enter only one value. If more than one field, how should I do?
My Output fields and values of the array!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community