public function update($object_name)
{
//rename table if necessary
$object = DB::table(DB_OBJECTS)->where('name', $object_name)->first();
$new_name = Str::slug(Input::get('name'), '_');
if ($object->name != $new_name) {
Schema::rename($object->name, $new_name);
}
//enforce predence always ascending
$order_by = Input::get('order_by');
$direction = Input::get('direction');
if ($order_by == 'precedence') {
$direction = 'asc';
}
//not sure why it's necessary, doesn't like empty value all of a sudden
$group_by_field = Input::has('group_by_field') ? Input::get('group_by_field') : null;
//linked objects
DB::table(DB_OBJECT_LINKS)->where('object_id', $object->id)->delete();
if (Input::has('related_objects')) {
foreach (Input::get('related_objects') as $linked_id) {
DB::table(DB_OBJECT_LINKS)->insert(['object_id' => $object->id, 'linked_id' => $linked_id]);
}
}
//update objects table
DB::table(DB_OBJECTS)->where('id', $object->id)->update(['title' => Input::get('title'), 'name' => $new_name, 'model' => Input::get('model'), 'url' => Input::get('url'), 'order_by' => $order_by, 'direction' => $direction, 'singleton' => Input::has('singleton') ? 1 : 0, 'can_see' => Input::has('can_see') ? 1 : 0, 'can_create' => Input::has('can_create') ? 1 : 0, 'can_edit' => Input::has('can_edit') ? 1 : 0, 'list_grouping' => Input::get('list_grouping'), 'group_by_field' => $group_by_field, 'list_help' => trim(Input::get('list_help')), 'form_help' => trim(Input::get('form_help'))]);
self::saveSchema();
return Redirect::action('InstanceController@index', $new_name);
}