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 !

HtmlBuilderController.php - Html Builder via Dependency Injection

IdNameEmailCreated AtUpdated At

Controller

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

/**
 * Datatables Html Builder
 * @var Builder
 */
protected $htmlBuilder;

public function __construct(Builder $htmlBuilder)
{
    $this->htmlBuilder = $htmlBuilder;
}

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

    $html = $this->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.basic', compact('html'));
}

View

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

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