mercredi 25 novembre 2015

Laravel Insert eloquent

Hy. I have a problem with Inserting eloquent laravel relation. Ok, Point

table :

## product ##
id
name_product

## market ##
id
idproduct
name_market

## product_market_a ##
id
id_market
value_market


## product_market_b ##
id
id_market
value_market


## product_market_c ##
id
id_market
value_market

and data post :

post = [
      ['value_market_a'=>'Value Market A'],
      ['value_market_b'=>'Value Market B'],
      ['value_market_c'=>'Value Market C],
      ['name_product'=>'Something']
]

example like that.

In controller :

$input = Input::all();

$product = new modelProduct();
$product->name_product = $input['name_product'];

$product->save();

$product_market_a = new modelMarketA();
$product_market_a->value_market = $input['value_market_a'];

$product_market_b = new modelMarketB();
$product_market_b->value_market = $input['value_market_b'];

$product_market_c = new modelMarketC();
$product_market_c->value_market = $input['value_market_c'];

$market_a = new modelMarket();
$market_b = new modelMarket();
$market_c = new modelMarket();

$market_a->name_market = 'Market A';
$market_b->name_market = 'Market B';
$market_c->name_market = 'Market C';

$product->toMarket->save($market_a);
$market_a->toMarketA->save($product_market_a);

$product->toMarket->save($market_b);
$market_b->toMarketB->save($product_market_b);

$product->toMarket->save($market_c);
$market_c->toMarketC->save($product_market_c);

like that my script. ok looked this

$product->toMarket->save($market_a);
$market_a->toMarketA->save($product_market_a);

$product->toMarket->save($market_b);
$market_b->toMarketB->save($product_market_b);

$product->toMarket->save($market_c);
$market_c->toMarketC->save($product_market_c);

in

$product->toMarket->save($market_a);
$product->toMarket->save($market_b);
$product->toMarket->save($market_c);

I wont in table market created / insert 3 record (market_a, market_b, market_c) with by holding the key product id. and then created / insert to product_market_a, product_market_b, product_market_c with by holding the key market id

this worked for me.. he save / insert with by holding the key marketid

$market_a->toMarketA->save($product_market_a);
$market_b->toMarketB->save($product_market_b);
$market_c->toMarketC->save($product_market_c);

Hmmm sorry if I messed language. thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1XhlRD3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire