Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

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 ?

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

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 ) ?

Last updated 1 year ago.
0

Load Group Fields : http://laravel.io/bin/okXra

Last updated 1 year ago.
0

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 !?

Last updated 1 year ago.
0

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!

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

m-alinasab m-alinasab Joined 14 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.