Donations Appreciated

There is no exercise better for the heart than reaching down and lifting people up. - John Holmes

Click here to lend your support to: Laravel Datatables and make a donation at pledgie.com !

EloquentController.php - Whitelist Columns

Sorting and searching will only work on columns explicitly defined as whitelist.

->whitelist(['name', 'email'])
Id Name Email Created At Updated At

EloquentController.php

    public function getWhitelist(Request $request)
    {
        if ($request->ajax()) {
            return Datatables::of(User::query())
                ->whitelist(['name', 'email'])
                ->make(true);
        }

        return view('datatables.eloquent.whitelist', ['title' => 'Whitelist Columns']);
    }

Javascript

    $('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: '',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'name', name: 'name'},
            {data: 'email', name: 'email'},
            {data: 'created_at', name: 'created_at'},
            {data: 'updated_at', name: 'updated_at'}
        ]
    });