2

I am working on a Module App in Laravel 5.3. I have setup module and It is working nice. My App directory structure is as below:

App
    |
    |_Http
    |
    |_Modules
       |_SMS
          |_Controllers
          |_Models
          |_Views

My question is, how I can make a controller in Modules/SMS/Controller folder from command line? I tried "php artisan make:controller App/Modules/SMS/Controller/Api/V1/UserController". But controller create in Http/Controller/Api/V1 directory. That is default Controller Directory. Thanks in Advance

2 Answers 2

3

You need to give the path in which you have to create the controller

php artisan make:controller pathName/controllerName

This will create controller in app/Http/Controller/YourPath/Controller

To Create it in Some Other Directory You need to do as Follows Inside app/Providers/RouteServiceProvider

Give Your New Default path in $namespace

protected $namespace = 'App\Http\Controllers';
//to
protected $namespace = 'New Default Path'

If you keep $namespace Blank Then every time you create controller You will have to give the path

Try This. Hope it works

Sign up to request clarification or add additional context in comments.

6 Comments

This Will Work You dont have to give entire Path just the folder name after the default path in which you have to create the controller ....Default path is app/Http/Controllers/
I have tried it like this php artisan make:controller MyPath\MyController and this creates the MyPathMyController.php file in app\controllers folder
yes you'll be getting you Mycontroller inside the controller folder due to the default path
it should be php artisan make:controller pathName/controllerName with forward slash
|
-1

You only need to pass the name of the subdirectory like this:

php artisan make:controller subDriectory/YourController php artisan make:controller subDriectory/YourController --plain

Please try it and see if it works :)

2 Comments

The "--plain" option does not exist.
It is not wroking

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.