Donations Appreciated

No one has ever become poor by giving. - Anne Frank, diary of Anne Frank

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

EloquentController.php - IoC container

Id Name Email Created At Updated At

EloquentController.php

    public function getIoc()
    {
        return view('datatables.eloquent.ioc');
    }

    public function getIocData()
    {
        $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at']);
        $datatables = app('datatables');

        return $datatables->eloquent($users)->make(true);
    }

    // OR via dependency injection
    public function getIocData(Datatables $datatables)
    {
        $users = User::select(['id', 'name', 'email', 'created_at', 'updated_at']);

        return $datatables->eloquent($users)->make(true);
    }

Javascript

    $('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: 'https://datatables.yajrabox.com/eloquent/ioc-data',
        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'}
        ]
    });