Skip to content

Commit 559b0c2

Browse files
authored
Update HasOrder.php
fix errors
1 parent 169ca58 commit 559b0c2

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Traits/HasOrder.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22

3-
namespace Alper\LaravelOrder\Traits;
3+
namespace App\Traits;
44

5-
use Alper\LaravelOrder\Services\OrderService;
5+
use App\Helpers\HelperServices\OrderService;
66
use Exception;
77
use Illuminate\Support\Facades\DB;
88
use Throwable;
99

10-
1110
/*
12-
* Requires integer and nullable attribute from Model Migration $orderAttrName in Model
11+
* Requires 'order' (integer and nullable) attribute from Model Migration
1312
* Gets optional $orderUnificationAttributes property from Model Class.
1413
* Gets optional orderAttrName property from Model Class default is 'order'.
1514
*/
15+
1616
trait HasOrder
1717
{
1818
#important: public string $orderAttrName = 'order';
@@ -60,6 +60,12 @@ protected static function boot(): void
6060
}
6161
DB::commit();
6262
});
63+
64+
static::created(
65+
function ($model) {
66+
OrderService::arrangeAllOrders($model);
67+
}
68+
);
6369
static::updated(/**
6470
* @throws Throwable
6571
*/ function ($model) {
@@ -70,7 +76,7 @@ protected static function boot(): void
7076
foreach ($model->orderUnificationAttributes as $attribute) {
7177
$q->where($attribute, $model->{$attribute});
7278
}
73-
})->whereNotNull($model->orderAttrName)
79+
})->whereNotNull($model->orderAttrName)->where('id', '!=', $model->id)
7480
->orderBy($model->orderAttrName)->get();
7581
$firstNumber = (int) $reSorts->first()->{$model->orderAttrName};
7682
if ($firstNumber === 0) {

0 commit comments

Comments
 (0)