Eloquent DataTable with Transformer

Id Name Email Created At Updated At Action

HTML

<table id="users-table" class="table table-bordered">
    <thead>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Email</th>
        <th>Created At</th>
        <th>Updated At</th>
        <th>Action</th>
    </tr>
    </thead>
</table>

Routes

<?php

Route::get('eloquent/transformer', 'Eloquent\TransformerController@index');
Route::get('eloquent/transformer-data', 'Eloquent\TransformerController@data');

Controller

<?php

namespace App\Http\Controllers\Eloquent;

use App\Http\Controllers\Controller;
use App\Transformers\UserTransformer;
use App\User;
use Yajra\Datatables\Datatables;

class TransformerController extends Controller
{
    /**
     * Display index page.
     *
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        return view('eloquent.transformer');
    }

    /**
     * Process dataTable ajax response.
     *
     * @param \Yajra\Datatables\Datatables $datatables
     * @return \Illuminate\Http\JsonResponse
     */
    public function data(Datatables $datatables)
    {
        return $datatables->eloquent(User::query())
                          ->setTransformer(new UserTransformer)
                          ->make(true);
    }
}

Transformer

<?php

namespace App\Transformers;

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

class UserTransformer extends TransformerAbstract
{
    public function transform(User $user)
    {
        return [
            'id'         => $user->id,
            'name'       => $user->name,
            'email'      => $user->email,
            'created_at' => $user->created_at,
            'updated_at' => $user->updated_at,
            'action'     => view('eloquent.tables.users-action', $user->toArray())->render(),
        ];
    }
}

JS