InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.79k stars 813 forks source link

[Feature]: Generate custom new file #471

Closed DylandeWit closed 2 years ago

DylandeWit commented 7 years ago

I would like te be able to generate a custom file along with the rest. The feature might be already there but I can't find it.

For example: testfile.stub -> to generate this file.

mitulgolakiya commented 7 years ago

@DylandeWit I don't think it's possible now. What we have right now is, you can publish existing templates and then make changes to the stub file, according to your need.

But we don't have support to generate extra files and I think this feature is already requested by someone in past and we already have it in the queue.

We have a plan to add a support for some hookup methods, where you can register your custom classes after/before/after some specific files with all data available which is available to each generator command.

skys215 commented 4 years ago

I think it's possible with php artisan infyom.publish:templates in new versions.

mitulgolakiya commented 2 years ago

@DylandeWit @skys215 As of the latest version, how you can accomplish this is,

  1. Read the new documentation here for Publishing Templates and understand how it works ( You don't need to publish templates if you do not want to customize existing templates and want to create new templates)
  2. Create a custom template file under a specific vendor view directory (laravel-generator or adminlte-templates or swagger-generator)
  3. All of our Generator classes are now injected through the service container of Laravel, so you can create your own class of Generator via extending the existing one
  4. Override the generate method
  5. Write a custom code to create a new stub file

And I think you should be able to create the custom file that you want.

Let me know if it helps.