LD 5 rokov pred
rodič
commit
f7e9028ca0

+ 8 - 1
app/Console/Commands/MakeServiceCommand.php

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
 
 use App\Traits\ServiceAppAop;
 use Illuminate\Console\Command;
+use Illuminate\Support\Str;
 
 class MakeServiceCommand extends Command
 {
@@ -43,7 +44,10 @@ class MakeServiceCommand extends Command
         if (!file_exists(base_path('app\\Services'))){
             mkdir('app\\Services',666,false);
         }
-        $fileName=$this->argument('name');
+        preg_match('/(.*?)Service/',$this->argument('name'),$resultNames);
+        $fileName=$resultNames[0];
+        $modelName=Str::studly($resultNames[1]);
+
         if (!file_exists(base_path('app\\Services\\'.$fileName.'.php'))){
             file_put_contents(base_path('app\\Services\\'.$fileName.'.php'),
                 '<?php '
@@ -53,6 +57,7 @@ class MakeServiceCommand extends Command
                 .PHP_EOL
                 .PHP_EOL
                 .'use App\Traits\ServiceAppAop;'
+                .'use App\\'.$modelName.';'
                 .PHP_EOL
                 .PHP_EOL
                 .'class '.$fileName
@@ -60,6 +65,7 @@ class MakeServiceCommand extends Command
                 .'{'
                 .PHP_EOL
                 .'    use ServiceAppAop;'
+                .'    protected $modelClass='.$modelName.'::class;'
                 .PHP_EOL
                 .PHP_EOL.
                 '}');
@@ -107,4 +113,5 @@ class MakeServiceCommand extends Command
         }
         $this->info("File create success!");
     }
+
 }