-
-
Notifications
You must be signed in to change notification settings - Fork 862
/
Copy pathApiResourceDataTable.php
46 lines (41 loc) · 1.43 KB
/
ApiResourceDataTable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Yajra\DataTables;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
class ApiResourceDataTable extends CollectionDataTable
{
/**
* Can the DataTable engine be created with these parameters.
*
* @param mixed $source
* @return bool
*/
public static function canCreate($source)
{
return $source instanceof AnonymousResourceCollection;
}
/**
* Factory method, create and return an instance for the DataTable engine.
*
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection<array-key, array>|array $source
* @return ApiResourceDataTable|DataTableAbstract
*/
public static function create($source)
{
return parent::create($source);
}
/**
* CollectionEngine constructor.
*
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection<array-key, array> $resourceCollection
*/
public function __construct(AnonymousResourceCollection $resourceCollection)
{
/** @var \Illuminate\Support\Collection<(int|string), array> $collection */
$collection = collect($resourceCollection)->pluck('resource');
$this->request = app('datatables.request');
$this->config = app('datatables.config');
$this->collection = $collection;
$this->original = $collection;
$this->columns = array_keys($this->serialize($collection->first()));
}
}