Query Builder DataTable using Buttons Plugin

IdNameEmailCreated AtUpdated AtAction

HTML

{!! $dataTable->table()  !!}

Routes

<?php

Route::resource('buttons/query', 'Buttons\QueryBuilderController');

Controller

<?php

namespace App\Http\Controllers\Buttons;

use App\DataTables\Buttons\UsersQueryBuilderDataTable;
use App\Http\Controllers\Controller;

class QueryBuilderController extends Controller
{
    /**
     * Display index page and process dataTable ajax request.
     *
     * @param \App\DataTables\Buttons\UsersQueryBuilderDataTable $dataTable
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    public function index(UsersQueryBuilderDataTable $dataTable)
    {
        return $dataTable->render('buttons.query.index');
    }

    /**
     * Show create user page.
     *
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function create()
    {
        return view('buttons.query.create');
    }
}

DataTable

<?php

namespace App\DataTables\Buttons;

use Illuminate\Support\Facades\DB;
use Yajra\Datatables\Services\DataTable;

class UsersQueryBuilderDataTable extends DataTable
{
    /**
     * Build DataTable class.
     *
     * @return \Yajra\Datatables\Engines\BaseEngine
     */
    public function dataTable()
    {
        return $this->datatables
            ->queryBuilder($this->query())
            ->addColumn('action', 'eloquent.tables.users-action');
    }

    /**
     * Get the query object to be processed by dataTables.
     *
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
     */
    public function query()
    {
        $query = DB::table('users');

        return $this->applyScopes($query);
    }

    /**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\Datatables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->columns($this->getColumns())
                    ->ajax('')
                    ->addAction(['width' => '80px'])
                    ->parameters($this->getBuilderParameters());
    }

    /**
     * Get columns.
     *
     * @return array
     */
    protected function getColumns()
    {
        return [
            'id',
            'name',
            'email',
            'created_at',
            'updated_at',
        ];
    }

    /**
     * Get filename for export.
     *
     * @return string
     */
    protected function filename()
    {
        return 'users_' . time();
    }
}

JS

{!! $dataTable->scripts() !!}