Skip to content

Commit

Permalink
Add using pivot option
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdekruijk authored Aug 11, 2023
1 parent 287b7fe commit 5aefbbd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Controllers/ModelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ private function save($model, Request $request)
$sync = [];
$morph = [];
$row = [];
$using = [];
foreach ($this->columns() as $columnId => $column) {
if (isset($column['type']) && $column['type'] == 'pivot') {
$sync[$column['model']] = $request[$columnId];
$using[$column['model']] = $column['using'] ?? null;
if (!empty($column['morph'])) {
$morph[$column['model']] = $column['morph'];
}
Expand Down Expand Up @@ -86,7 +88,7 @@ private function save($model, Request $request)
if (isset($morph[$foreign])) {
$model->morphToMany($foreign, $morph[$foreign])->sync($values);
} else {
$model->belongsToMany($foreign)->sync($values);
$model->belongsToMany($foreign)->using($using[$foreign])->sync($values);
}
}

Expand Down

0 comments on commit 5aefbbd

Please sign in to comment.