public function afterSave($project, $attributes)
    {
        // if "relation" is not present in the input, we simply detach all
        // related models by passing an empty array.
        $ids = isset($attributes['relation']) ? $attributes['relation'] : [];
        $project->manyToManyRelation()->sync($ids);
    }
public function afterSave($project, $attributes)
    {
        // if "relation" is not present in the input, we simply detach all
        // related models by passing an empty array.
        $ids = isset($attributes['relation']) ? $attributes['relation'] : [];
        $project->manyToManyRelation()->sync($ids);
    }
public function afterSave ( $ project , $ attributes ) { // if "relation" is not present in the input, we simply detach all // related models by passing an empty array. $ ids = isset ( $ attributes [ 'relation' ] ) ? $ attributes [ 'relation' ] : [ ] ; $ project -> manyToManyRelation ( ) -> sync ( $ ids ) ; }
Using afterSave, afterCreate or afterUpdate to set relationships is
often very useful. afterSave is called on both update and create.
Using afterSave afterCreate or afterUpdate to set relationships is often very useful . afterSave is called on both update and create .