23

I want to create a model in a custom path. If i write the php artisan command like the following it will create model inside app.

php artisan make:model core

But i want to create the model file inside the custom made Models folder. How can i do it ?

1
  • Please note that this question is written for a Laravel version lower than version 8. Since in that version, the default folder for models has been changed to be app/Models by default, just like OP of the question wants. laravel-news.com/new-features-coming-to-laravel-8 Commented Oct 31, 2022 at 12:52

2 Answers 2

56

Just define the path where you want to create model.

php artisan make:model <directory_name>/<model_name>

e.g.

php artisan make:model Models/core
Sign up to request clarification or add additional context in comments.

3 Comments

If i create a folder inside the Models folder, then what will be the command ? Is it php artisan make:model Models/Core/core
Note that migration will utilize <model_name>, "core" in this case. So it may conflict if you use directories to differ namespace
@Saleh Ahmad Oyon, just Core/Core, to create inside Models another folder, which contains the Core.php class
5

You can do it easily with custom directory of your Models Folder (I assume Models Folder is sub folder of App). Just use this command php artisan make:model Models/core then you will get your desire result.
Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.