我怎样才能从两行中添加变量?

时间:2020-02-07 10:09:10

标签: php laravel datatables

我在数据表中的重复位置有问题。 我有订单表 id | order_no |状态|等

和具有订单所有者的第二张表。每个订单可以有多个所有者。

在laravel控制器中,我有这样的代码:

$orders = DB::table('orders')

        ->join('order_addresses', 'orders.id', '=', 'order_addresses.order_id')
        ->join('customers', 'orders.id_client', '=', 'customers.id')

        ->join('order_owners', 'orders.id', '=', 'order_owners.order_id')
       'users.name as username', 'orders.comment', 'order_addresses.country')
        ->select('orders.id', 'orders.order_no', 'orders.deadline', 'customers.name as customersname', 'orders.comment', 'order_addresses.country')

        ->get();


        return Datatables($orders)->make(true);```

and in view this

var url =“订单/显示”;

  var table = $('#orders').DataTable({
        "processing": true,
        "serverSide": true,

        "ajax": {
            "dataType": "json",
            "url": url,
            "data": function(outData) {
                // what is being sent to the server
                console.log('i');
                console.log(outData);
                return outData;

            },
            dataFilter: function(inData) {
                // what is being sent back from the server (if no error)
                console.log('i2');
                console.log(inData);
                return inData;
            },
            error: function(err, status) {
                // what error is seen(it could be either server side or client side.
                console.log('i3');
                console.log(err);
            },

        },

        "columns": [{
            sortable: false,
            "render": function(data, type, full, meta) {

                return '<span class="badge badge-danger"></span>';
            }
          },
            {
                "name": "id",
                "data": ".id"
            },
            {
                "name": "order_no",
                "data": "order_no"
            },
            {
                "name": "deadline",
                "data": "deadline"
            },
            {
                "name": "customersname",
                "data": "customersname"
            },
            {
                "name": "country",
                "data": "country"
            },
            {
                "name": "comment",
                "data": "comment"
            },



            {
                sortable: false,
                "render": function(data, type, full, meta) {
                    var buttonID = full.id;
                    return '<a href="/orders/' + full.id + '/edit" class="btn btn-primary" role="button">edit</a>';
                }
            },
        ],


    });

当我按顺序添加2个所有者时,我得到重复的数据表

image

那么,我如何在一行中将此2位所有者添加到一列中?

0 个答案:

没有答案