public function index() { if (!Auth::check()) { return LoginController::getIndex(); } LoginController::updateUserPermissions(); //why not # Trail Trail::clear(); $tables = array_where(config('center.tables'), function ($key, $value) { return !$value->hidden && LoginController::checkPermission($value->name, 'view'); }); $groups = $objects = []; foreach ($tables as $table) { $latest = DB::table($table->name)->leftJoin(config('center.db.users') . ' as u2', $table->name . '.updated_by', '=', 'u2.id')->select('u2.name as updated_name', $table->name . '.updated_at')->orderBy($table->name . '.updated_at', 'desc')->first(); if (!isset($groups[$table->list_grouping])) { $groups[$table->list_grouping] = []; } $groups[$table->list_grouping][] = (object) ['title' => $table->title, 'list_grouping' => $table->list_grouping, 'link' => action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name), 'updated_name' => isset($latest->updated_name) ? $latest->updated_name : '', 'updated_at' => isset($latest->updated_at) ? $latest->updated_at : '', 'count' => number_format(DB::table($table->name)->count())]; } foreach ($groups as $group) { $objects = array_merge($objects, $group); } $table = new Table(); $table->rows($objects); $table->column('title', 'string', trans('center::site.table')); $table->column('count', 'integer', trans('center::site.count')); $table->column('updated_name', 'updated_name', trans('center::site.updated_name')); $table->column('updated_at', 'updated_at', trans('center::site.updated_at')); $table->groupBy('list_grouping'); $table = $table->draw('tables'); return view('center::tables.index', compact('table')); }
public static function table($table, $columns, $rows) { if (count($rows)) { $return = new Table(); $return->rows($rows); foreach ($columns as $column) { $return->column($column->name, $column->type, $column->title); } if (LoginController::checkPermission($table->name, 'edit')) { if (isset($table->fields->deleted_at)) { $return->deletable(); } if (array_keys($table->order_by)[0] == $table->name . '.precedence') { $return->draggable(action('\\LeftRight\\Center\\Controllers\\RowController@reorder', $table->name)); } } if (!empty($table->group_by)) { $return->groupBy('group'); } return $return->draw($table->name); } }