Yousef Altaf Yousef Altaf - 5 months ago 20
PHP Question

Generating model by JeffreyWay Generators, can't specify the path

Every time I generate a model using Jeffrey Way's Generators library, the models gets created in the "app/" directory. For example, I've run the following:

php artisan generate:model vision


This gets created in the "app/" directory.

I would like to have the model get created in a "models" directory, so I tried this:

php artisan generate:model --path="models" vision


However, I get the following error:

file_put_contents(models/Vision.php): failed to open stream: No such file or directory


generate:model [--path="..."] [--templatePath="..."] modelName


How can I do this?
enter image description here

Answer

In this version of the library, it appears that the specified path must exist before using it. I was able to replicate your experience as shown below:

[chris@little-mac:four-dot-two]$ php artisan generate:model vision
Created: /Users/chris/Projects/four-dot-two/app/models/Vision.php
[chris@little-mac:four-dot-two]$ php artisan generate:model --path="models" vision



  [ErrorException]                                                             
  file_put_contents(models/Vision.php): failed to open stream: No such file o  
  r directory                                                                  



generate:model [--path="..."] [--templatePath="..."] modelName

To resolve it, I simply created a "models" directory at the framework root.

[chris@little-mac:four-dot-two]$ mkdir models
[chris@little-mac:four-dot-two]$ php artisan generate:model --path="models" vision
Created: models/Vision.php
[chris@little-mac:four-dot-two]$