php - Laravel and polymorphic -


i try first polymorphic relationships , managed record think pivot entry.

i have basic "brands" nike or philips, "valeur" quality or compliance , classic "users" base.

i have " valuables" supposed contain input value of "brands" user, therefore structure of database :

id valeur_id (integer) user_id (integer) valuable_id (integer) valuable_type (string) 

with little knowledge, can save entry correct value of brand not id of user.

value model

public function brand ( $user ) {     return $this->morphedbymany(' brand', ' valuable '); } 

brand model

public function valeur() {     return $this->morphtomany( 'valeur ', ' valuable '); } 

i record entry this:

brand::where( 'slug', $search)->first(); $id = auth::user()->id; $valeur = valeur::find(3);  $brand->valeur()->save( $valeur ); 

i want "just" associated valeur -> brand user id , please me?

thank in advance

you can pass array second argument save, data store in pivot table:

$brand->valeur()->save($valeur, array('user_id' => $id)); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -