@@ -34,7 +34,7 @@ public function directoryCreate()
3434 public function generateController ()
3535 {
3636 if (! file_exists (base_path ('app/Http/Controllers/Api/ ' .$ this ->model .'Controller.php ' ))) {
37- $ template = file_get_contents ( self ::STUB_DIR . 'controller.stub ' );
37+ $ template = self ::getStubContents ( 'controller.stub ' );
3838 $ template = str_replace ('{{modelName}} ' , $ this ->model , $ template );
3939 $ template = str_replace ('{{modelNameLower}} ' , strtolower ($ this ->model ), $ template );
4040 $ template = str_replace ('{{modelNameCamel}} ' , Str::camel ($ this ->model ), $ template );
@@ -48,7 +48,7 @@ public function generateController()
4848 public function generateResource ()
4949 {
5050 if (! file_exists (base_path ('app/Http/Resources/ ' .$ this ->model .'Resource.php ' ))) {
51- $ template = file_get_contents ( self ::STUB_DIR . 'resource.stub ' );
51+ $ template = self ::getStubContents ( 'resource.stub ' );
5252 $ template = str_replace ('{{modelName}} ' , $ this ->model , $ template );
5353 file_put_contents (base_path ('app/Http/Resources/ ' .$ this ->model .'Resource.php ' ), $ template );
5454 $ this ->result = true ;
@@ -60,7 +60,7 @@ public function generateResource()
6060 public function generateCollection ()
6161 {
6262 if (! file_exists (base_path ('app/Http/Resources/ ' .$ this ->model .'Collection.php ' ))) {
63- $ template = file_get_contents ( self ::STUB_DIR . 'collection.stub ' );
63+ $ template = self ::getStubContents ( 'collection.stub ' );
6464 $ template = str_replace ('{{modelName}} ' , $ this ->model , $ template );
6565 file_put_contents (base_path ('app/Http/Resources/ ' .$ this ->model .'Collection.php ' ), $ template );
6666 $ this ->result = true ;
@@ -81,4 +81,8 @@ public function generateRoute()
8181
8282 return $ this ->result ;
8383 }
84+
85+ private function getStubContents ($ stubName ){
86+ return file_get_contents (self ::STUB_DIR .$ stubName );
87+ }
8488}
0 commit comments