File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 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 ;
66use Exception ;
77use Illuminate \Support \Facades \DB ;
88use 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+
1616trait 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 ) {
You can’t perform that action at this time.
0 commit comments