laravel背包增删改查在列表视图中显示关系过滤器和更新

fut*_*web 0 laravel laravel-backpack

如何在列表中显示关系字段并按其过滤并更新视图?

假设我有一个交易表

Id, customer_id,  product_id, purchase_date, payment_status
Run Code Online (Sandbox Code Playgroud)

一张顾客桌

Id, first_name, last_name, email, password
Run Code Online (Sandbox Code Playgroud)

产品表

Id, product_name, product_description, product_price, stock
Run Code Online (Sandbox Code Playgroud)

例如。我想在我的交易视图中显示:

ID, customer.first_name customer.last_name, product.product_name, purchase_date, payment_status
Run Code Online (Sandbox Code Playgroud)

并想按客户名称和产品名称过滤结果,我已阅读文档但不知道如何实现这一点。

rob*_*yrr 5

在 CrudController 的 setup() 方法中:

$this->crud->setListView('your-custom-view');
Run Code Online (Sandbox Code Playgroud)

如果需要,您可以使用默认列表视图作为启动器并对其进行修改

你可以在vendor/backpack/crud/src/resources/views/list.blade.php中找到默认文件。

不要在那里修改它,因为它将显示在所有 Crud 视图上。只需将其作为模板并将“您的自定义视图”保存在视图中即可。

也许这会有所帮助:https://laravel-backpack.readme.io/v3.3/docs/filters

编辑:

您想要客户的名字等等,而不是 customer_id,对吗?这就能解决问题:

在你的 TransactionCrudController 中:

$this->crud->addColumn([
        // 1-n relationship
        'label' => "customer", // Table column heading
        'type' => "select",
        'name' => 'customer_id', // the column that contains the ID of that connected entity;
        'entity' => 'customer', // the method that defines the relationship in your Model
        'attribute' => "first_name", // foreign key attribute that is shown to user
        'model' => "App/Models/Customer", // foreign key model
    ]);
Run Code Online (Sandbox Code Playgroud)

这是你想要的?如果没有请告诉我。