Kameam
Kameam

Reputation: 81

Unknown paramater name when calling data in datatable

When I call the data to view, an error appear said that "...Requested unknown paramater 'name'..." Here is My controller

public function TeamTask(Request $request)
    {
          if ($request->ajax()) {
            $data = Post::select(DB::raw('count(user_id) as total'))->selectRaw('SUM(status = "Finish") as finish')->groupBy('name')->get();
            return Datatables::of($data)
                ->addIndexColumn()
                ->make(true);
        }

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

Here is my view

<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: 'total',
                    name: 'total',
                    orderable: false,
                },
                {
                    data: 'finish',
                    name: 'finish'
                },

            ]
        });

    });

</script>

When I call the data to view, an error appear said that "...Requested unknown paramater 'name'..." Is something wrong in my controller or my view? thanks in advance

Upvotes: 0

Views: 26

Answers (1)

Vysco Zyza
Vysco Zyza

Reputation: 119

use this query

$data = DB::table('posts')->select('name', DB::raw('count(user_id) as total'))->selectRaw('SUM(status = "Finish") as finish')->groupBy('name')->get();

Upvotes: 1

Related Questions