Skip to content

Commit

Permalink
Add defaultPositionValue property
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Jun 11, 2018
1 parent e362b60 commit aeac2c6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ You can set:
* *string* `positionColumn` *to enable overriding for the position column*
* *boolean* `disablePositionUpdate` *disables the updated of other entries*
* *string|array* `positionGroup` *builds a filter from columns for position calculation. Supports single column or multiple columns*
* *string* `defaultPositionValue` *allows returning different value when position is empty string or null. Default value is null*

#### PositionScopeTrait

Expand Down
3 changes: 2 additions & 1 deletion src/Traits/BasePositionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function setPosition($value)
protected function setPositionAttribute($value)
{
// Convert to numeric value if needed
$finalValue = is_null($value) || $value === '' ? null : intval($value);
$finalValue = is_null($value) || $value === '' ?
$this->positionOption('defaultPositionValue', null) : intval($value);

$this->attributes['position'] = $finalValue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/PositionTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Pion\Support\Eloquent\Position\Traits;

use Pion\Support\Eloquent\Position\PositionObserver;
Expand All @@ -8,6 +9,7 @@
/**
* Trait PositionTrait
*
* @property mixed defaultPositionValue Setup default value
* @property array attributes
* @property string positionColumn to enable overriding for the position column
* @property boolean disablePositionUpdate disables the updated of other entries
Expand Down

0 comments on commit aeac2c6

Please sign in to comment.