File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -106,20 +106,23 @@ public function handle()
106106
107107 // check if it already uses CrudTrait
108108 // if it does, do nothing
109- if (Str:: contains ( $ content, $ this ->crudTrait )) {
109+ if ($ content-> contains ( $ this ->crudTrait )) {
110110 $ this ->closeProgressBlock ('Already existed ' , 'yellow ' );
111111
112112 return false ;
113113 } else {
114- $ modifiedContent = Str::of (Str:: before ( $ content, '; ' ))
114+ $ modifiedContent = Str::of ($ content-> before ( '; ' ))
115115 ->append ('; ' .PHP_EOL .PHP_EOL .'use Backpack\CRUD\app\Models\Traits\CrudTrait; ' );
116116
117117 $ content = $ content ->after ('; ' );
118118
119- $ hasNewLine = str_starts_with ($ content , '\n ' ) ? 1 : 0 ;
119+ $ hasNewLine = str_starts_with ($ content , '\n\n ' ) ? 1 : 0 ;
120120
121121 $ modifiedContent = $ modifiedContent ->append (substr ($ content , strpos ($ content , "\n" ) + $ hasNewLine ));
122122
123+ // use the CrudTrait on the class
124+ $ modifiedContent = $ modifiedContent ->replaceFirst ('{ ' , '{ ' .PHP_EOL .' use CrudTrait; ' );
125+
123126 // save the file
124127 $ this ->files ->put ($ path , $ modifiedContent );
125128 // let the user know what we've done
You can’t perform that action at this time.
0 commit comments