无法获取user_id值Laravel查询

胡涛

我无法使用数据表在视图页面中调用user_id,当我将select('name')更改为select('user_id')或select('*')时,它也显示错误DataTables warning: table id=DataTables_Table_0 - Ajax error. For more information about this error, please see http://datatables.net/tn/7我的代码出了什么问题?提前致谢

我有一个控制器,包含以下代码

public function TeamTask(Request $request)
    {
      
        if ($request->ajax()) {
            $data = DB::table('posts')->select('name')->selectraw('count(user_id) as total')->selectRaw('SUM(status = "Done") as done')->where('div',  Auth::user()->div)->groupBy('name')->get();
            return Datatables::of($data)
                ->addColumn('action', function ($row) {

                    $btn = ' <a href="javascript:void(0)" data-toggle="tooltip"  data-id="' . $row->name . '" data-original-title="Detail" class="btn btn-success mr-1 btn-sm detailProduct"><span class="fas fa-info"></span></a>';

                    return $btn;
                })
                ->rawColumns(['action'])
                ->addIndexColumn()
                ->make(true);
        }

        return view('task.teamTask',);
    }

我的看法

<script type="text/javascript">
    $(function() {

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        var table = $('.data-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: "{{ route('team.task') }}",

            columns: [{
                    data: 'DT_RowIndex',
                    name: 'DT_RowIndex',
                    orderable: false,
                    searchable: false,
                },
                {
                    data: 'name',
                    name: 'name',
                    orderable: false,
                },
                {
                    data: 'user_id',
                    name: 'user_id',
                    orderable: false,
                },
                {
                    data: 'total',
                    name: 'total',
                    orderable: false,
                },
                {
                    data: 'done',
                    name: 'done'
                },
                {
                    data: 'action',
                    name: 'action'
                },

            ]
        });

    });
</script>

我无法使用数据表在视图页面中调用user_id,当我将select('name')更改为select('user_id')或select('*')时,它也显示错误DataTables warning: table id=DataTables_Table_0 - Ajax error. For more information about this error, please see http://datatables.net/tn/7我的代码出了什么问题?提前致谢

Vysco Zyza

添加->groupBy('user_id')您的查询,这应该可以解决您的问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过USER_ID获取节点(查询)

给定user_id的postgreSQL排名查询

从 Facebook url 获取任何 user_id

无法将user_id和product_id插入购物车。Laravel 5

无法写入未知属性`user_id`

如何获取数据库中特定行的相应user_id(自动增量)值?

PHP-检查数组中是否存在JSON值,如果存在,则获取关联的user_id

根据 Laravel 数据库中的 user_id 获取城市值

如何在laravel护照api中获取带有访问令牌的user_id?

如何从laravel 5.3的user_id获取用户名?

尝试使用user_id Laravel从用户模型获取用户名

Laravel 5.4中的'user_id'没有默认值错误

“一般错误:1364 字段‘user_id’没有默认值”Laravel

为每个 user_id 查找最大 id 的 SQL 查询

MySQL查询,获取user_ID,然后获取Restaurant_ID,然后从与用户表中的电子邮件匹配的3个表中获取restaurantName

如何在 Oracle Apex 中获取当前 user_id

如何使用php从mysql获取当前的user_id?

如何从当前登录的用户那里获取user_id?

telethon通过user_id获取access_hass

获取用户或user_id Soundcloud API

通过user_id获取Google Plus封面URL

如何获取当前登录用户的user_id

如何使用与 JavaScript 匹配的 user_id 从 Firebase 获取数据

无法使用RSpec / Rails测试SessionsController规范中POST #create中设置的session [:user_id]值

MySql按user_id获取页面列表,或者如果未定义user_id,则获取所有页面

ActiveModel :: MissingAttributeError(无法写入未知属性“ user_id”)

无法读取未定义的属性“ user_id”

如何獲得user_id的“雪花”值?

如何控制Devise user_id值分配