I have following tables:
Expand|Select|Wrap|Line Numbers
- document: id, name;
- author: id, name, job_title;
- document_author: document_id, author_id, position
Expand|Select|Wrap|Line Numbers
- $attributes = [name, job_title, position];
- I'm trying to create author's model and attach it to document:
Expand|Select|Wrap|Line Numbers
- $author = \Author::create($attributes);
- \Document::find($id)->authors()->save($author,$attributes);
The only I got is to filter array, like that:
Expand|Select|Wrap|Line Numbers
- $author = \Author::create($attributes);
- $pivotAttributes = array_only($attributes, ['position'])
- \Document::find($id)->authors()->save($author,$pivotAttributes);