-
-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2870 from hpacleb/fix-anonymous-resource-collection
Fix anonymous resource collection
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?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> $collection | ||
*/ | ||
public function __construct(AnonymousResourceCollection $collection) | ||
{ | ||
$this->request = app('datatables.request'); | ||
$this->config = app('datatables.config'); | ||
$this->collection = collect($collection); | ||
$this->original = collect($collection); | ||
$this->columns = array_keys($this->serialize(collect($collection)->first())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters