argument('name'); if (!file_exists(base_path('app\\Services\\'.$fileName.'.php'))){ file_put_contents(base_path('app\\Services\\'.$fileName.'.php'), 'error("ERROR: file exists;"); if ($this->option("provider")){ $path = base_path("app\\Providers\\AppServiceProvider.php"); $i = 0; $fop = fopen($path,"r+"); $endLine = 0; $startLine = 0; while (!feof($fop)){ $i += 1; $lineStr = fgets($fop); if (strpos($lineStr,"app()->singleton"))$endLine = $i; if (strpos($lineStr,"App\Services"))$startLine = $i; }; fclose($fop); $fop = fopen($path,"r+"); $i = 0; $arr = []; while (!feof($fop)){ $i += 1; $lineStr = fgets($fop); if ($i == $endLine){ $lineStr = $lineStr." app()->singleton('{$fileName}',{$fileName}::class);".PHP_EOL; } if ($i == $startLine){ $lineStr = $lineStr."use App\Services\\$fileName;".PHP_EOL; } $arr[] = $lineStr; }; fclose($fop); unlink($path); foreach ($arr as $value){ file_put_contents($path,$value,FILE_APPEND); } } $this->info("File create success!"); } }