/** * Execute the console command. * * @return mixed */ public function fire() { $table1 = $this->option('table1'); $table2 = $this->option('table2'); $fields = $this->option('fields'); if ($fields) { $fields = explode(',', $fields); } else { $fields = '*'; } $op = new Operation(compact('table1', 'table2', 'fields')); $op->save(); $op->getDiffProcessor()->intoTempTable($op->id); $this->info("Diff #{$op->id} ready."); }
public function getShow($id) { /** @var Operation $operation $op */ $operation = Operation::findOrFail($id); Model::$current_table = $operation->getDiffTableAttribute(); $model = new Model(); $query = $model->newQuery(); $diff = $operation->getDiffProcessor(); foreach ($diff->getPkColumns() as $name) { $query->addSelect($name); } foreach ($diff->getDiffColumns() as $name) { $query->addSelect("{$name}_1"); $query->addSelect("{$name}_2"); $query->addSelect(DB::raw("{$name}_1 - {$name}_2 as {$name}_diff")); } $dp = new EloquentDataProvider($query); $config = new GridConfig(); $config->setDataProvider($dp); foreach ($diff->getPkColumns() as $name) { $config->addColumn((new FieldConfig())->setName($name)->setSortable(true)->addFilter(new FilterConfig())); } foreach ($diff->getDiffColumns() as $name) { $config->addColumn((new FieldConfig())->setName("{$name}_1")->setSortable(true)); $config->addColumn((new FieldConfig())->setName("{$name}_2")->setSortable(true)); $config->addColumn((new FieldConfig())->setName("{$name}_diff")->setSortable(true)); } $config->getComponentByName(THead::NAME)->addComponent((new OneCellRow())->setComponents([new RecordsPerPage(), new ColumnsHider(), new RenderFunc(function () { return ' <button class="btn btn-primary"> <span class="glyphicon glyphicon-filter"></span> Filter </button>'; })])->setRenderSection(THead::SECTION_END)); $grid = new Grid($config); return \View::make('db-diff::show', compact('grid', 'operation')); }