JL
Add value to field in pivot table in CreateAction
Yes, the code is in SubcategoriesRelationManager
I get it:
->headerActions([
CreateAction::make()
->using(function (array $data, string $model): Model {
$table = $this->getTable();
$relationship = $table->getRelationship();
$pivotData = [];
$pivotColumns = $relationship->getPivotColumns();
$pivotData = Arr::only($data, $pivotColumns);
$data = Arr::except($data, $pivotColumns);
$parentCategory = $relationship->getParent();
$pivotData['pivotorder'] = $relationship->max('pivotorder') + 1;
$record = new $model();
$record->fill($data);
$relationship->save($record, $pivotData);
return $record;
})
])
Now that I can debug it was easier 🙂 but surely there is a better way to do it than copy and paste 🙂
Very thanks
6 replies