title: laravel custom command to generate file
body: <p>I came across this article on Spatie Actions <a href="https://freek.dev/1371-refactoring-to-actions" rel="nofollow noreferrer">https://freek.dev/1371-refactoring-to-actions</a> and I would like to make a command to generate the files for me, similar how you can generate Model or livewire components etc.</p>
  <pre><code>php artisan make:action PublishPostAction Post
  </code></pre>
  <p>This is as far as I got</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Console\Commands;
  
  use Illuminate\Console\Command;
  
  class GenerateActionTemplate extends Command
  {
      /**
       * The name and signature of the console command.
       *
       * @var string
       */
      protected $signature = 'make:action {name} {model}';
  
      /**
       * The console command description.
       *
       * @var string
       */
      protected $description = 'Create a new action file.';
  
      /**
       * Execute the console command.
       *
       * @return int
       */
      public function handle()
      {
          $name = $this-&gt;argument('name');
          $model = $this-&gt;argument('model');
  
          $fileContents = &lt;&lt;&lt;'EOT'
          &lt;?php
  
          namespace App\Actions;
  
          class PublishPostAction // name
          {
              private $post;
  
              public function execute(Post $post) // model
              {
                  $this-&gt;post = $post;
              }
  
          }
  
          EOT;
  
          $this-&gt;info($name . 'has been created successfully!');
      }
  }
  </code></pre>
  <ul>
  <li>How would I do the logic, so if I do like <code>make:action post.PublishPostAction</code> would create a new folder called post in <code>App\Actions\Post\</code></li>
  <li>In the EOT how would I pass in the variables?</li>
  </ul>
  <p>Any help or link to an example would be great! I have looked through a few tutorials and was able to scrap this up and laravel docs don't really show any example to generate a new file.</p>