Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.79 KB

README.md

File metadata and controls

56 lines (42 loc) · 1.79 KB

DataTables Server-Side API for Laravel Framework

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.