Laravel Create Model Outside App Namespace

- 1 answer

I want to use the command php artisan make:model User for creating an user inside the domain folder. Nevertheless it will end up in the App folder.

I've already tried this:

  • php artisan make:model Domain\User
  • php artisan make:model Domain\\User
  • php artisan make:model \\Domain\\User
  • php artisan make:model Domain/User

app folder:

 +-- App
 +-- Domain
 +-- Http

composer file:

"autoload": {
    "psr-4": {
      "App\\": "app/App/",
      "Domain\\": "app/Domain/",
      "Http\\": "app/Http/",
      "Support\\": "app/Support/"


php artisan make:model ../Domain/User solved the problem for model. I have stil the problem with a controller php artisan make:controller ../Http/UserController



Not sure why you need to create a model outside the default location.

Artisan make commands will attempt to store the files in the standard location according to the command you running.

As an example, php artisan make:model User will create the model inside app directory (default directory for models). So assuming the desired destination for your model is one directory above and has the name Domain you can run the following command:

php artisan make:model ../Domain/User

Note that ../Domain/ is relative to the default location for that command.

For a controller, knowing the default directory is app/http/Controller and you want to generate a controller in Domain/http/Controller you can do it with the following command:

php artisan make:controller ../../../Domain/Http/UserController

Please note that this isn't usual and is not following the standards.

Hape that helps you with what you are trying to achieve