It looks like you are calling the function incorrectly or from an uninitialized model. The error says that profile_id is NULL. Therefore, if you call a function like $profile->setTagsAttribute() , you need to make sure that $ profile is initialized in the database with the identifier.
$profile = new Profile; //will fail because $profile->id is NULL //INSERT: profile->save() or Profile::Create(); $profile->setTagsAttribute(array(1,2,3));
In addition, you can pass an array to the attach function to attach several models at the same time:
$this->tags()->attach($tag_ids);
You can also pass it a model instead of an ID (but a fairly confident array of models won't work)
Tonyarra
source share