Generate Model, Controller outside of app folder in Laravel

二次信任 提交于 2021-02-17 02:32:30

问题


How to create controller and model files outside of app folder. For example, when we do

php artisan make:model ModelName

it creates Model file inside app folder. When we specify namespace like

php artisan make:model SomeFolder/ModelName

it creates Model file inside app/SomeFolder/ModelName.

I wanted to create model files outside of app folder. How to achieve this?


回答1:


I don't see the reason, but I managed to make it on my local computer by php artisan make:model ../../mOdel . Probably in production environment you won't be allowed to do this.




回答2:


Yes you can achieve this via below steps:

1) Change psr-4 value for 'App' into composer.json file

2) Run composer dump-autoload command for load composer

3) Run command for manually created model php artisan make:model yourfoldername/model

NOTE: Make sure, whenever you create model using command you need to change namespace.



来源:https://stackoverflow.com/questions/39068241/generate-model-controller-outside-of-app-folder-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!