@@ -16,27 +16,52 @@ class RepositoryCommand extends Command
1616 */
1717 public function handle ()
1818 {
19+ $ this ->line ('' );
20+ $ this ->info ('🔨 Repository Generator ' );
21+ $ this ->line ('------------------------------------- ' );
22+
1923 $ name = $ this ->argument ('name ' );
2024 $ modelName = $ this ->option ('model ' );
21-
2225 $ className = Str::studly ($ name );
2326
27+ // Table rows
28+ $ rows = [
29+ ['📦 Repository Name ' , "<info> {$ className }</info> " ],
30+ ];
31+
32+ if ($ modelName ) {
33+ $ rows [] = ['🗂️ Using Model ' , "<comment> {$ modelName }</comment> " ];
34+ }
35+
36+ $ folderPath = app_path ('Repositories ' );
37+ if (!file_exists ($ folderPath )) {
38+ mkdir ($ folderPath );
39+ $ rows [] = ['📂 Created Folder ' , '<comment>app/Repositories</comment> ' ];
40+ }
41+
2442 $ repositoryPath = app_path ("Repositories/ {$ className }.php " );
2543
2644 if (file_exists ($ repositoryPath )) {
27- return $ this ->error ('Repository already exits. ' );
45+ $ this ->error ("❌ Repository already exists " );
46+ $ this ->line ("📍 Location: <comment> {$ repositoryPath }</comment> " );
47+ return 1 ;
2848 }
2949
50+ // Prepare stub
3051 if ($ modelName ) {
3152 $ modelVariable = Str::camel ($ modelName );
32- $ stub = file_get_contents (__DIR__ . '/../../stubs/repository.model.stub ' );
53+ $ stub = file_get_contents (__DIR__ . '/../../stubs/repository.model.stub ' );
3354 if (file_exists (base_path ('stubs/repository.model.stub ' ))) {
3455 $ stub = file_get_contents (base_path ('stubs/repository.model.stub ' ));
3556 }
3657
37- $ stub = str_replace (['{{ ClassName }} ' , '{{ modelName }} ' , '{{ modelVariable }} ' ], [$ className , $ modelName , $ modelVariable ], $ stub );
58+ $ stub = str_replace (
59+ ['{{ ClassName }} ' , '{{ modelName }} ' , '{{ modelVariable }} ' ],
60+ [$ className , $ modelName , $ modelVariable ],
61+ $ stub
62+ );
3863 } else {
39- $ path = __DIR__ . '/../../stubs/repository.stub ' ;
64+ $ path = __DIR__ . '/../../stubs/repository.stub ' ;
4065 $ stub = file_get_contents ($ path );
4166 if (file_exists (base_path ('stubs/repository.stub ' ))) {
4267 $ stub = file_get_contents (base_path ('stubs/repository.stub ' ));
@@ -46,8 +71,19 @@ public function handle()
4671
4772 file_put_contents ($ repositoryPath , $ stub );
4873
49- $ returnPath = "app/Repositories/ {$ className }.php " ;
74+ // Add success to table
75+ $ rows [] = ['✅ Repository Created ' , "<comment>app/Repositories/ {$ className }.php</comment> " ];
76+
77+ // Print as table
78+ $ this ->table (
79+ ['Action ' , 'Details ' ],
80+ $ rows
81+ );
82+
83+ $ this ->newLine ();
84+ $ this ->info ('🎉 Done! Your repository is ready to use. ' );
85+ $ this ->newLine ();
5086
51- $ this -> info ( " Repository [ { $ returnPath } ] created successfully " ) ;
87+ return 0 ;
5288 }
5389}
0 commit comments