SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ deposits.Country”

时间:2019-11-05 07:45:40

标签: json laravel datatable

我正在正确地获取数据。但是当我尝试在数据表中搜索时,它给了我上面的错误..未知列..如果它不能正常工作一次,我就没有得到它,那么为什么它在搜索时给出错误

$deposits2 = DB::connection('mysql')    
    ->table('deposits')
    ->join('users','users.id','=','deposits.user_id')
    ->select('deposits.*','users.Country')
    ->where('deposits.status','Approved');

Here is the error

这是我的视图文件中的代码

<script>
$(document).ready( function () {

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

        "ajax": {
            "url": "{{url('dashboard/adeposits/json')}}",
            "type": "GET"
        },
        "deferRender": true,

        "columns":
            [
                { "data" : "id", "title" : "Portfolio#", "searchable": true,

                    "render": function ( data, type, row, meta ) {
                        var itemID = data;
                        return '<a data-toggle="modal" data-target="#DDetailsModal" href="#" onclick="viewDetailsFunc('+row.id+')">D-'+itemID+'</a>';
                    }
                },
                { "data" : "unique_id", "title" : "UserID", "orderable": true, "searchable": true },
                { "data" : "Country", "title" : "Country", "orderable": true, "searchable": true },

2 个答案:

答案 0 :(得分:0)

$deposits2 = DB::connection('mysql')    
                   ->table('deposits')
                   ->select('deposits.*','users.Country')
                   ->join('users','users.id','=','deposits.user_id')
                   ->where('deposits.status','Approved')
                   ->get();

答案 1 :(得分:0)

在数据表中,您可以在列中设置字段名称。

{ "data" : "Country", name: "users.Country", "title" : "Country", "orderable": true, "searchable": true },