GenerateMCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class GenerateMCommand extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'generatem
  12. {path: /path/to/models.json}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command description';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. //
  36. global $argv;
  37. $models = json_decode(file_get_contents($argv[2]));
  38. $template = file_get_contents(base_path('generatecv/model.template.php'));
  39. foreach ($models as $model) {
  40. $name = str_replace(" ", "", ucwords(str_replace("_", " ", $model)));
  41. $text = str_replace("_NAME_", $name, $template);
  42. $text = str_replace("_TABLE_", $model, $text);
  43. if(!file_exists(app_path("Models/$name.php"))) {
  44. file_put_contents(app_path("Models/$name.php"), $text);
  45. echo "Generated " . app_path("Models/$name.php") . "\n";
  46. }
  47. }
  48. }
  49. }