ad-mos/laravel-datatables

DataTables Server-Side API for Laravel Framework

v2.7 2024-04-17 13:52 UTC

This package is auto-updated.

Last update: 2024-10-17 15:02:47 UTC


README

Laravel 5.x Latest Stable Version StyleCI Scrutinizer Code Quality License

Quick Installation

$ composer require ad-mos/laravel-datatables

Usage examples

1 - Simple table:

public function data(DataTables $dataTables)
{
    return $dataTables->provide(new User);
}

2 - Table with joins:

public function data(DataTables $dataTables)
{
    $model = new User;

    $query = $model->newQuery()
        ->leftJoin('user_emails', 'user_emails.user_id', '=', 'users.id')
        ->leftJoin('user_phones', 'user_phones.user_id', '=', 'users.id')
        ->groupBy('users.id');

    $aliases = [
        'emails' => 'GROUP_CONCAT(DISTINCT `user_emails`.email SEPARATOR \'|\')',
        'phones' => 'GROUP_CONCAT(DISTINCT `user_phones`.phone SEPARATOR \'|\')',
    ];

    return $dataTables->provide($this->model, $query, $aliases);
}

DataTables can be accessed through IoC, helper or facade:

return $dataTables->provide(...);

return datatables()->provide(...);

return \DataTables::provide(...);

License

The MIT License. More information here.