lundi 28 novembre 2016

How does associate work?

Im trying to get associate to work.

Relationship on User model:

public function group()
{
    return $this->belongsTo('User');
}

So I do:

$user = new User();
//save user fields
....
$user->save();

$group = Group::find(1);
$user->group()->associate($group);

A new user is inserted, but in the FK of group_id on the user table I am getting null.



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

Aucun commentaire:

Enregistrer un commentaire