77
88class CrudModelBackpackCommand extends GeneratorCommand
99{
10+ use \Backpack \CRUD \app \Console \Commands \Traits \PrettyCommandOutput;
11+
1012 /**
1113 * The console command name.
1214 *
@@ -55,6 +57,8 @@ public function handle()
5557 $ namespaceApp = $ this ->qualifyClass ($ this ->getNameInput ());
5658 $ namespaceModels = $ this ->qualifyClass ('/Models/ ' .$ this ->getNameInput ());
5759
60+ $ this ->progressBlock ("Creating $ namespaceModels " );
61+
5862 // Check if exists on app or models
5963 $ existsOnApp = $ this ->alreadyExists ($ namespaceApp );
6064 $ existsOnModels = $ this ->alreadyExists ($ namespaceModels );
@@ -67,11 +71,14 @@ public function handle()
6771
6872 $ this ->files ->put ($ this ->getPath ($ namespaceModels ), $ this ->sortImports ($ this ->buildClass ($ namespaceModels )));
6973
70- $ this ->info ( $ this -> type . ' created successfully. ' );
74+ $ this ->closeProgressBlock ( );
7175
7276 return ;
7377 }
7478
79+ // Model exists
80+ $ this ->closeProgressBlock ('Already existed ' , 'yellow ' );
81+
7582 // If it was found on both namespaces, we'll ask user to pick one of them
7683 if ($ existsOnApp && $ existsOnModels ) {
7784 $ result = $ this ->choice ('Multiple models with this name were found, which one do you want to use? ' , [
@@ -90,13 +97,15 @@ public function handle()
9097 // As the class already exists, we don't want to create the class and overwrite the
9198 // user's code. We just make sure it uses CrudTrait. We add that one line.
9299 if (! $ this ->hasOption ('force ' ) || ! $ this ->option ('force ' )) {
100+ $ this ->progressBlock ('Adding CrudTrait to model ' );
101+
93102 $ file = $ this ->files ->get ($ path );
94103 $ lines = preg_split ('/(\r\n)|\r|\n/ ' , $ file );
95104
96105 // check if it already uses CrudTrait
97106 // if it does, do nothing
98107 if (Str::contains ($ file , $ this ->crudTrait )) {
99- $ this ->comment ( ' Model already used CrudTrait. ' );
108+ $ this ->closeProgressBlock ( ' Already existed ' , ' yellow ' );
100109
101110 return ;
102111 }
@@ -123,14 +132,15 @@ public function handle()
123132 $ this ->files ->put ($ path , implode (PHP_EOL , $ lines ));
124133
125134 // let the user know what we've done
126- $ this ->info ( ' Model already existed. Added CrudTrait to it. ' );
135+ $ this ->closeProgressBlock ( );
127136
128137 return ;
129138 }
130139 }
131140
132141 // In case we couldn't add the CrudTrait
133- $ this ->error ("Model already existed on ' $ name' and we couldn't add CrudTrait. Please add it manually. " );
142+ $ this ->errorProgressBlock ();
143+ $ this ->note ("Model already existed on ' $ name' and we couldn't add CrudTrait. Please add it manually. " , 'red ' );
134144 }
135145 }
136146
0 commit comments