Donations Appreciated

We only have what we give. - Isabel Allende

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

EloquentController.php - Fractal Transformer

Id Name Email Created At Updated At


    public function getTransformer()
        return view('datatables.eloquent.transformer');

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

        return Datatables::of($users)
            ->setTransformer(new \App\Transformers\UserTransformer)


        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'}


namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\User;

class UserTransformer extends TransformerAbstract
     * @return  array
    public function transform(User $user)
        return [
            'id'         => (int) $user->id,
            'name'       => $user->name,
            'email'      => $user->email,
            'created_at' => (string) $user->created_at,
            'updated_at' => (string) $user->updated_at,