关系表背包laravel的addColumn

时间:2018-12-12 13:21:39

标签: laravel backpack-for-laravel

在我的项目中,我有两个用于产品对象的表:products(产品,sku,价格,可用等)和product_description(名称,描述等)。

表结构 产品展示 https://prnt.sc/lu03kg

product_description https://prnt.sc/lu0436

我尝试通过此代码在ProductDescriptionCrudController中添加列。

import java.io.*;
import java.util.*;

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class EditorOpener {

    public static void main(String[] args) {
        final Map<String, String> getenv = System.getenv();
        System.out.println(getenv);

        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setSize(500, 200);
        shell.setText("Editor Opener");
        shell.setLayout(new RowLayout());

        final Button button = new Button(shell, SWT.PUSH);
        button.setText("open gedit");

        button.addListener(SWT.Selection, event -> new Thread(() -> {
            final ProcessBuilder processBuilder = new ProcessBuilder();
            processBuilder.command("/usr/bin/gedit");
            final Map<String, String> environment = processBuilder.environment();
            System.out.println(environment);
            try {
                final Process process = processBuilder.start();
                process.waitFor();
            }
            catch (IOException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }).start());

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}

但是我得到了产品的ID。我在做什么错了?

价格方法的addField工作正常

$this->crud->addColumn([
'label' => 'Price',
'type' => 'number',
'name' => 'id',
'entity' => 'product',
'attribute' => 'price',
'model' => 'App\Models\Product'
]);

谢谢!

1 个答案:

答案 0 :(得分:0)

我在您的“ product_description”表中没有看到与“产品”的关系的列。在您的ProductDescription模型中拥有该列,您可能会:

$(function() {
  $('.down-checkbox').change(function() {
    $('.badge-danger').closest('tr').toggle(this.checked);
  });
});

因此,在清单中,使用“ name”参数指定关系的列:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="text-default">
  <input type="checkbox" class="down-checkbox" id="down" checked>
  <label for="down">Only show offline servers</label>
</span>
<table>
  <thead>
    <tr>
      <th>No.</th>
      <th>Server</th>
      <th>URL</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>test</td>
      <td>test.test.test</td>
      <td><span class="badge badge-success">LIVE</span></td>
    </tr>
    <tr>
      <td>2</td>
      <td>test</td>
      <td>test.test.test</td>
      <td><span class="badge badge-danger">DOWN</span></td>
    </tr>
    <tr>
      <td>3</td>
      <td>test</td>
      <td>test.test.test</td>
      <td><span class="badge badge-success">LIVE</span></td>
    </tr>
    <tr>
      <td>4</td>
      <td>test</td>
      <td>test.test.test</td>
      <td><span class="badge badge-danger">DOWN</span></td>
    </tr>
  </tbody>
</table>