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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire