首页 文章

laravel backpack crud显示关系列表视图过滤和更新

提问于
浏览
0

如何在列表和更新视图中显示关系字段和过滤器?

假设我有一个交易表

Id, customer_id,  product_id, purchase_date, payment_status

客户表

Id, first_name, last_name, email, password

产品表

Id, product_name, product_description, product_price, stock

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

ID, customer.first_name customer.last_name, product.product_name, purchase_date, payment_status

并希望按客户名称和产品名称过滤结果,我已经阅读了文档并且无法看到如何实现这一点 .

1 回答

  • 1

    在您的CrudController中的setup()方法中:

    $this->crud->setListView('your-custom-view');
    

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

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

    不要在那里进行修改,因为它会在所有Crud视图中显示 . 只需将其作为模板并在视图中保存“你的自定义视图” .

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

    Edit:

    而不是customer_id,你想要客户first_name等等吗?这样就可以了:

    在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
        ]);
    

    这是你想要的?如果没有让我知道 .

相关问题