Skip to content

Instantly share code, notes, and snippets.

@reachkamrul
Created May 13, 2020 12:20
Show Gist options
  • Save reachkamrul/8053d7e5e61d006650f42d0e96f6a09d to your computer and use it in GitHub Desktop.
Save reachkamrul/8053d7e5e61d006650f42d0e96f6a09d to your computer and use it in GitHub Desktop.
add_filter('ninja_tables_item_attributes', function ($attributes) {
$latest = ninja_tables_DbTable()->where('table_id', $attributes['table_id'])->orderBy('id', 'DESC')->limit(1)->first();
$value = json_decode($attributes['value'], true);
if ($latest) {
$latest = json_decode($latest->value, true);
if (isset($latest['id']) && isset($value['id'])) {
$value['id'] = $latest['id'] + 1;
}
} else {
$value['id'] = 1;
}
$attributes['value'] = json_encode($value);
return $attributes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment