Donations Appreciated

You have not lived today until you have done something for someone who can never repay you. - John Bunyan

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

HtmlBuilderController.php - Html Builder via Method Injection

IdNameEmailCreated AtUpdated At

Controller

use Yajra\Datatables\Html\Builder; // import class on controller

public function getBasic(Request $request, Builder $htmlBuilder)
{
    if ($request->ajax()) {
        return Datatables::of(User::select(['id', 'name', 'email', 'created_at', 'updated_at']))->make(true);
    }

    $html = $htmlBuilder
        ->addColumn(['data' => 'id', 'name' => 'id', 'title' => 'Id'])
        ->addColumn(['data' => 'name', 'name' => 'name', 'title' => 'Name'])
        ->addColumn(['data' => 'email', 'name' => 'email', 'title' => 'Email'])
        ->addColumn(['data' => 'created_at', 'name' => 'created_at', 'title' => 'Created At'])
        ->addColumn(['data' => 'updated_at', 'name' => 'updated_at', 'title' => 'Updated At']);

    return view('datatables.html.method', compact('html'));
}

View

@section('demo')
    {!! $html->table() !!}
@endsection

@section('scripts')
    {!! $html->scripts() !!}
@endsection