Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize models templates #119

Closed
mixartemev opened this issue Sep 21, 2018 · 4 comments
Closed

Add ability to customize models templates #119

mixartemev opened this issue Sep 21, 2018 · 4 comments

Comments

@mixartemev
Copy link

It would be very convenient to customize the template itself

@CristianLlanos
Copy link
Member

What kind of customisation you have in mind? Do you have an example?

@mixartemev
Copy link
Author

I propose move templates from vendor/reliese/laravel/src/Coders/Model/Templates/ to resources/generators/templates/ in user app.
That could he edit templates himself and save it for further use and channging.

@ParatechX
Copy link

Thanks Cristian for making this package available! It is saving me lots time right now.

If anyone else stumbles across this in search for template customization, this might help:
The code already includes an option via the config. The Factory.php->prepareTemplate() looks for *.template.model as an alternative to the default file. Not sure if it is intentional, or a bug, but the config lookup resolves to searching for *.*.template.model so it can be tricky to get it working without knowing that.

Anyhow, this is what I added at the top of my config/model.php file:

'*' => [
    '*' => [
        'template' => array( 
            'model' => app_path('CustomLibsPath') . '/resources/stubs/whatever.stub',
        ),
    ],

whatever.stub just contains the original content from Coders/Model/model plus any customizations. In my case I just wanted to add a simple line in the comment block.

Hope that helps anyone trying to customize the template to a limited extend.

@CristianLlanos
Copy link
Member

Great hack! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants