7
7
use Bnb \Laravel \Sequence \Jobs \UpdateSequence ;
8
8
use DB ;
9
9
use Illuminate \Database \Eloquent \SoftDeletes ;
10
+ use Illuminate \Support \Str ;
10
11
11
12
trait HasSequence
12
13
{
@@ -65,7 +66,7 @@ protected function canGenerateSequenceNumber($name)
65
66
{
66
67
$ authorized = true ;
67
68
68
- if (method_exists ($ this , $ method = 'canGenerate ' . ucfirst (camel_case ($ name )) . 'Sequence ' )) {
69
+ if (method_exists ($ this , $ method = 'canGenerate ' . ucfirst (Str:: camel ($ name )) . 'Sequence ' )) {
69
70
$ authorized = ! ! $ this ->{$ method }();
70
71
}
71
72
@@ -94,7 +95,7 @@ public function generateSequenceNumber($name = null, $save = true)
94
95
95
96
if ($ saved = $ this ->save ()) {
96
97
collect ($ generated )->each (function ($ name ) {
97
- $ this ->fireModelEvent (sprintf ('sequence_%s_generated ' , studly_case ($ name )), false );
98
+ $ this ->fireModelEvent (sprintf ('sequence_%s_generated ' , Str:: studly ($ name )), false );
98
99
});
99
100
}
100
101
@@ -108,7 +109,7 @@ public function generateSequenceNumber($name = null, $save = true)
108
109
if ($ this ->canGenerateSequenceNumber ($ name )) {
109
110
$ sequence = null ;
110
111
111
- if (method_exists ($ this , $ method = 'is ' . ucfirst (camel_case ($ name )) . 'GapFilling ' ) && $ this ->{$ method }()) {
112
+ if (method_exists ($ this , $ method = 'is ' . ucfirst (Str:: camel ($ name )) . 'GapFilling ' ) && $ this ->{$ method }()) {
112
113
$ start = $ this ->generateSequenceStartValue ($ name ) - 1 ;
113
114
114
115
$ sequence = DB ::selectOne (DB ::raw (<<<SQL
@@ -141,7 +142,7 @@ public function generateSequenceNumber($name = null, $save = true)
141
142
142
143
$ next = intval ($ next );
143
144
144
- if (method_exists ($ this , $ method = 'format ' . ucfirst (camel_case ($ name )) . 'Sequence ' )) {
145
+ if (method_exists ($ this , $ method = 'format ' . ucfirst (Str:: camel ($ name )) . 'Sequence ' )) {
145
146
$ next = $ this ->{$ method }($ next , $ sequence ->last_sequence_value );
146
147
147
148
if ( ! preg_match ('/^\d{1,10}$/ ' , $ next )) {
@@ -157,7 +158,7 @@ public function generateSequenceNumber($name = null, $save = true)
157
158
158
159
if ($ save ) {
159
160
if ($ this ->save ()) {
160
- $ this ->fireModelEvent (sprintf ('sequence_%s_generated ' , studly_case ($ name )), false );
161
+ $ this ->fireModelEvent (sprintf ('sequence_%s_generated ' , Str:: studly ($ name )), false );
161
162
}
162
163
}
163
164
@@ -176,7 +177,7 @@ public function generateSequenceNumber($name = null, $save = true)
176
177
*/
177
178
public static function sequenceGenerated ($ name , $ callback )
178
179
{
179
- static ::registerModelEvent (sprintf ('sequence_%s_generated ' , studly_case ($ name )), $ callback );
180
+ static ::registerModelEvent (sprintf ('sequence_%s_generated ' , Str:: studly ($ name )), $ callback );
180
181
}
181
182
182
183
@@ -189,7 +190,7 @@ protected function generateSequenceStartValue($name)
189
190
{
190
191
$ defaultStart = config ('sequence.start ' , 1 );
191
192
192
- if (method_exists ($ this , $ method = 'get ' . ucfirst (camel_case ($ name )) . 'StartValue ' )) {
193
+ if (method_exists ($ this , $ method = 'get ' . ucfirst (Str:: camel ($ name )) . 'StartValue ' )) {
193
194
$ defaultStart = $ this ->{$ method }();
194
195
}
195
196
@@ -205,7 +206,7 @@ protected function handleSoftDeletedSequence($name, $save = true)
205
206
get_class ($ this )
206
207
));
207
208
208
- $ isGapFilling = method_exists ($ this , $ method = 'is ' . ucfirst (camel_case ($ name )) . 'GapFilling ' ) && $ this ->{$ method }();
209
+ $ isGapFilling = method_exists ($ this , $ method = 'is ' . ucfirst (Str:: camel ($ name )) . 'GapFilling ' ) && $ this ->{$ method }();
209
210
210
211
if ($ this ->exists () && $ isSoftDelete && $ isGapFilling && ! is_null ($ this ->{$ this ->getDeletedAtColumn ()}) && $ this ->{$ name }) {
211
212
$ this ->{$ name } = null ;
0 commit comments