Closed vesper8 closed 2 years ago
@vesper8 currently, there is no way to do this, I will take it in a queue and will add a support for it.
This would be good idea. Any update on this?
There is no update on this. We will think to add it soon.
Just added support for this in the latest version v5.3.0.
You can add dynamic variables to the generator config by calling addDynamicVariables
method in the service provider's boot method. For e.g,
Add the following code in the AppServiceProvider
boot method,
GeneratorConfig::addDynamicVariable('testVar', 'testVal');
Alternatively, you can add multiple variables as well by,
GeneratorConfig::addDynamicVariables(['testVar1' => 'testVal1', 'testVar2' => 'testVal2']);
Once variables are added, you can publish templates and then modify the view file to use the variable,
protected $dynamicVars = [
'testVal' => '{{ $config->getDynamicVariable('testVar') }}',
];
As per the new release, $config
is injected in every view stub file that the generator uses.
Let me know if any further explanations or suggestions are there.
In GeneratorConfig.php at the bottom of the loadDynamicVariables function you have this
This is a useful way of adding new dynamic variables. I have added a few of them myself that I use in my customized stubs.
However this forces me to make edits inside of the /vendor folder which is bad practice.
Would it be possible to add an array "dynamic_variables" inside of laravel_generator.php and iterate through it in GeneratorConfig.php so that we could add our own dynamic variables via the configuration file?
Please and thank you :)