sukohi/datatable-resource
Composer 安装命令:
composer require sukohi/datatable-resource
包简介
A Laravel package that provides data for Datatable which is jQuery plugin with pagination.
README 文档
README
A Laravel package that provides resource data for Datatable which is jQuery plugin with pagination.
This package is for Datatable and maintained under Laravel 6.x.
Installation
composer require sukohi/datatable-resource:1.*
Usage
Basic usage
// in Route
Route::get('item_resource', function(){
$query = \App\Item::query();
// Of course you can add any methods here like `where()`, `orderBy()` and even `with()`.
return new DatatableResource($query);
});
Now you can get JSON data that Datatable needs.
with additional values
return new DatatableResource($query, [
'key_1' => 'value_1',
'key_2' => 'value_2',
'key_3' => 'value_3',
]);
Trait
This package contains DatatableResourceTrait that provides kind of useful methods.
In order to use them, set DatatableResourceTrait into your Model as follows.
use Sukohi\DatatableResource\Traits\DatatableResourceTrait;
class class Item extends Model
{
use DatatableResourceTrait;
hasDatatableSearch()
Check if current access has search parameters.
if($this->hasDatatableSearch()) {
// Do something...
}
getDatatableSearchKeywords()
You can get search keywords that Datatable submitted.
$keywords = $this->getDatatableSearchKeywords();
foreach($keywords as $keyword) {
// Do someting...
}
hasDatatableSort()
Check if current access has sort parameters.
if($this->hasDatatableSort()) {
// Do something...
}
getDatatableSort()
You can get sort parameters that Datatable submitted.
$order_by = $this->getDatatableSort();
// Usage
$column = $order_by->column;
$direction = $order_by->direction;
License
This package is licensed under the MIT License.
Copyright 2020 Sukohi Kuhoh
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-12