Skip to content

Commit aeac2c6

Browse files
committed
Add defaultPositionValue property
1 parent e362b60 commit aeac2c6

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ You can set:
142142
* *string* `positionColumn` *to enable overriding for the position column*
143143
* *boolean* `disablePositionUpdate` *disables the updated of other entries*
144144
* *string|array* `positionGroup` *builds a filter from columns for position calculation. Supports single column or multiple columns*
145+
* *string* `defaultPositionValue` *allows returning different value when position is empty string or null. Default value is null*
145146

146147
#### PositionScopeTrait
147148

src/Traits/BasePositionTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function setPosition($value)
4848
protected function setPositionAttribute($value)
4949
{
5050
// Convert to numeric value if needed
51-
$finalValue = is_null($value) || $value === '' ? null : intval($value);
51+
$finalValue = is_null($value) || $value === '' ?
52+
$this->positionOption('defaultPositionValue', null) : intval($value);
5253

5354
$this->attributes['position'] = $finalValue;
5455
}

src/Traits/PositionTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Pion\Support\Eloquent\Position\Traits;
34

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

0 commit comments

Comments
 (0)