File tree 1 file changed +11
-5
lines changed
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- namespace Alper \ LaravelOrder \Traits ;
3
+ namespace App \Traits ;
4
4
5
- use Alper \ LaravelOrder \ Services \OrderService ;
5
+ use App \ Helpers \ HelperServices \OrderService ;
6
6
use Exception ;
7
7
use Illuminate \Support \Facades \DB ;
8
8
use Throwable ;
9
9
10
-
11
10
/*
12
- * Requires integer and nullable attribute from Model Migration $orderAttrName in Model
11
+ * Requires 'order' ( integer and nullable) attribute from Model Migration
13
12
* Gets optional $orderUnificationAttributes property from Model Class.
14
13
* Gets optional orderAttrName property from Model Class default is 'order'.
15
14
*/
15
+
16
16
trait HasOrder
17
17
{
18
18
#important: public string $orderAttrName = 'order';
@@ -60,6 +60,12 @@ protected static function boot(): void
60
60
}
61
61
DB ::commit ();
62
62
});
63
+
64
+ static ::created (
65
+ function ($ model ) {
66
+ OrderService::arrangeAllOrders ($ model );
67
+ }
68
+ );
63
69
static ::updated (/**
64
70
* @throws Throwable
65
71
*/ function ($ model ) {
@@ -70,7 +76,7 @@ protected static function boot(): void
70
76
foreach ($ model ->orderUnificationAttributes as $ attribute ) {
71
77
$ q ->where ($ attribute , $ model ->{$ attribute });
72
78
}
73
- })->whereNotNull ($ model ->orderAttrName )
79
+ })->whereNotNull ($ model ->orderAttrName )-> where ( ' id ' , ' != ' , $ model -> id )
74
80
->orderBy ($ model ->orderAttrName )->get ();
75
81
$ firstNumber = (int ) $ reSorts ->first ()->{$ model ->orderAttrName };
76
82
if ($ firstNumber === 0 ) {
You can’t perform that action at this time.
0 commit comments