Skip to content

Commit

Permalink
Merge branch '8.0'
Browse files Browse the repository at this point in the history
* 8.0:
  Bump v8.4.4 🚀
  [8.0] Fixed a bug for "undefined index" errors (#1728)
  Adds support to Laravel 5.6 on readme
  Use array_key_exists instead of in_array + array_keys
  Bump v8.4.3 🚀
  Update EloquentDataTable.php
  Bump v8.4.2 🚀
  Add mention of Datatables Editor pkg to "suggests"
  code style issues fix
  Support SoftDeletes on join
  Revert "adding softdelete support to hasOne and belongsTo relations"
  adding softdelete support to hasOne and belongsTo relations
  • Loading branch information
yajra committed May 4, 2018
2 parents e64fb3c + 7cf086f commit ac2ac09
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

### [Unreleased]

### [v8.4.4] - 2018-05-04

- Use array_key_exists instead of in_array + array_keys [#1719], credits to [@carusogabriel].
- Adds support to Laravel 5.6 on readme, [#1724], credits to [@nunomaduro]
- Fixed a bug for "undefined index" errors, [#1728], credits to [@redelschaap]

### [v8.4.3] - 2018-04-05

- [8.0] Fix ambiguous column 'deleted_at'. [#1688], credits to [@sskl].

### [v8.4.2] - 2018-03-29

- Check SoftDeletes on HasOne or BelongsTo relations [#1628], credits to [@drahosistvan].
- Add mention of Datatables Editor pkg to "suggests" [#1658], credits to [@drbyte].

### [v8.4.1] - 2018-02-16

- Change Log contract to LoggerInterface. [#1624], credits to [@LEI].
Expand Down Expand Up @@ -172,7 +187,10 @@ return (new CollectionDataTable(User::all())->toJson();
- Fix orderColumn api where related tables are not joined.
- Fix nested with relation search and sort function.

[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v8.4.1...8.0
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v8.4.4...8.0
[v8.4.4]: https://github.com/yajra/laravel-datatables/compare/v8.4.3...v8.4.4
[v8.4.3]: https://github.com/yajra/laravel-datatables/compare/v8.4.2...v8.4.3
[v8.4.2]: https://github.com/yajra/laravel-datatables/compare/v8.4.1...v8.4.2
[v8.4.1]: https://github.com/yajra/laravel-datatables/compare/v8.4.0...v8.4.1
[v8.4.0]: https://github.com/yajra/laravel-datatables/compare/v8.3.3...v8.4.0
[v8.3.3]: https://github.com/yajra/laravel-datatables/compare/v8.3.2...v8.3.3
Expand All @@ -187,6 +205,12 @@ return (new CollectionDataTable(User::all())->toJson();
[v8.0.1]: https://github.com/yajra/laravel-datatables/compare/v8.0.0...v8.0.1
[v8.0.0]: https://github.com/yajra/laravel-datatables/compare/v7.10.1...v8.0.0

[#1728]: https://github.com/yajra/laravel-datatables/pull/1728
[#1724]: https://github.com/yajra/laravel-datatables/pull/1724
[#1719]: https://github.com/yajra/laravel-datatables/pull/1719
[#1688]: https://github.com/yajra/laravel-datatables/pull/1688
[#1658]: https://github.com/yajra/laravel-datatables/pull/1658
[#1628]: https://github.com/yajra/laravel-datatables/pull/1628
[#1624]: https://github.com/yajra/laravel-datatables/pull/1624
[#1609]: https://github.com/yajra/laravel-datatables/pull/1609
[#1492]: https://github.com/yajra/laravel-datatables/pull/1492
Expand Down Expand Up @@ -232,6 +256,9 @@ return (new CollectionDataTable(User::all())->toJson();

[laravel-datatables-fractal]: https://github.com/yajra/laravel-datatables-fractal

[@sskl]: https://github.com/sskl
[@drbyte]: https://github.com/drbyte
[@drahosistvan]: https://github.com/drahosistvan
[@LEI]: https://github.com/LEI
[@marcoocram]: https://github.com/marcoocram
[@ElfSundae]: https://github.com/ElfSundae
Expand All @@ -240,3 +267,5 @@ return (new CollectionDataTable(User::all())->toJson();
[@pimlie]: https://github.com/pimlie
[@jiwom]: https://github.com/jiwom
[@Oussama-Tn]: https://github.com/Oussama-Tn
[@redelschaap]: https://github.com/redelschaap
[@nunomaduro]: https://github.com/nunomaduro
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ return datatables(User::all())->toJson();

## Requirements
- [PHP >= 7.0](http://php.net/)
- [Laravel 5.4|5.5](https://github.com/laravel/framework)
- [Laravel 5.4|5.5|5.6](https://github.com/laravel/framework)
- [jQuery DataTables v1.10.x](http://datatables.net/)

## Documentations
Expand All @@ -50,6 +50,7 @@ return datatables(User::all())->toJson();
5.3.x | 6.x
5.4.x | 7.x, 8.x
5.5.x | 8.x
5.6.x | 8.x

## DataTables 8.x Upgrade Guide
There are breaking changes since DataTables v8.x.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"suggest": {
"yajra/laravel-datatables-buttons": "Plugin for server-side exporting of dataTable.",
"yajra/laravel-datatables-html": "Plugin for server-side HTML builder of dataTable.",
"yajra/laravel-datatables-fractal": "Plugin for server-side response using Fractal."
"yajra/laravel-datatables-fractal": "Plugin for server-side response using Fractal.",
"yajra/laravel-datatables-editor": "Plugin to use Datatables Editor (requires a license)."
},
"autoload": {
"psr-4": {
Expand Down
35 changes: 26 additions & 9 deletions src/EloquentDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function resolveRelationColumn($column)
protected function isNotEagerLoaded($relation)
{
return ! $relation
|| ! in_array($relation, array_keys($this->query->getEagerLoads()))
|| ! array_key_exists($relation, $this->query->getEagerLoads())
|| $relation === $this->query->getModel()->getTable();
}

Expand All @@ -138,6 +138,7 @@ protected function isNotEagerLoaded($relation)
protected function joinEagerLoadedColumn($relation, $relationColumn)
{
$table = '';
$deletedAt = false;
$lastQuery = $this->query;
foreach (explode('.', $relation) as $eachRelation) {
$model = $lastQuery->getRelation($eachRelation);
Expand All @@ -160,36 +161,48 @@ protected function joinEagerLoadedColumn($relation, $relationColumn)
break;

case $model instanceof HasOneOrMany:
$table = $model->getRelated()->getTable();
$foreign = $model->getQualifiedForeignKeyName();
$other = $model->getQualifiedParentKeyName();
$table = $model->getRelated()->getTable();
$foreign = $model->getQualifiedForeignKeyName();
$other = $model->getQualifiedParentKeyName();
$deletedAt = $this->checkSoftDeletesOnModel($model->getRelated());
break;

case $model instanceof BelongsTo:
$table = $model->getRelated()->getTable();
$foreign = $model->getQualifiedForeignKey();
$other = $model->getQualifiedOwnerKeyName();
$table = $model->getRelated()->getTable();
$foreign = $model->getQualifiedForeignKey();
$other = $model->getQualifiedOwnerKeyName();
$deletedAt = $this->checkSoftDeletesOnModel($model->getRelated());
break;

default:
throw new Exception('Relation ' . get_class($model) . ' is not yet supported.');
}
$this->performJoin($table, $foreign, $other);
$this->performJoin($table, $foreign, $other, $deletedAt);
$lastQuery = $model->getQuery();
}

return $table . '.' . $relationColumn;
}

protected function checkSoftDeletesOnModel($model)
{
if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($model))) {
return $model->getQualifiedDeletedAtColumn();
}

return false;
}

/**
* Perform join query.
*
* @param string $table
* @param string $foreign
* @param string $other
* @param string $deletedAt
* @param string $type
*/
protected function performJoin($table, $foreign, $other, $type = 'left')
protected function performJoin($table, $foreign, $other, $deletedAt = false, $type = 'left')
{
$joins = [];
foreach ((array) $this->getBaseQueryBuilder()->joins as $key => $join) {
Expand All @@ -199,5 +212,9 @@ protected function performJoin($table, $foreign, $other, $type = 'left')
if (! in_array($table, $joins)) {
$this->getBaseQueryBuilder()->join($table, $foreign, '=', $other, $type);
}

if ($deletedAt !== false) {
$this->getBaseQueryBuilder()->whereNull($deletedAt);
}
}
}
9 changes: 6 additions & 3 deletions src/Utilities/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ public static function getOrMethod($method)
public static function convertToArray($row)
{
$data = $row instanceof Arrayable ? $row->toArray() : (array) $row;
foreach (array_keys($data) as $key) {
if (is_object($data[$key]) || is_array($data[$key])) {
$data[$key] = self::convertToArray($data[$key]);

foreach ($data as &$value) {
if (is_object($value) || is_array($value)) {
$value = self::convertToArray($value);
}

unset($value);
}

return $data;
Expand Down

0 comments on commit ac2ac09

Please sign in to comment.