Framework: Generate namespaced resource controllers

Created on 2 Apr 2013  路  5Comments  路  Source: laravel/framework

php artisan controller:make API\UserController, generates controllers\APIUserController.php, instead op controllers\API\UserController.php.

And instead of
class APIUserController extends BaseController {
it should be
namespace API; class UserController extends \BaseController {

Wouldn't it make sense to use the namespace? Or perhaps an option like php artisan controller:make UserController --namespace=API (but that seems unnecessary verbose)

Most helpful comment

I use php artisan make:controller Api/Admin/UserController, it works, too.

If you type \ in your shell, shell will try to escape \, i.e.
echo Api\Admin\UserController will actually print ApiAdminUserController

This is a non-issue related to laravel

All 5 comments

I just tried this out, am I doing something wrong?

php artisan make:controller \Api\Admin\UserController produced ApiAdminUserController.php

so I tried:

php artisan make:controller \\Api\\Admin\\UserController, which created the right directories, but the namespace was malformed namespace App\Http\Controllers\\Api\Admin;

My base controller namespace in RouteServiceProvider.php looks like this: protected $namespace = 'App\Http\Controllers';

EDIT: nevermind.. it's correct, I had a leading \\ in the namespace when I generated the controller indicating the root; makes sense

I have the same problem

@jmarcher try php artisan make:controller Api\\Admin\\UserController

@amitailanciano thanks, works like a charm!

I use php artisan make:controller Api/Admin/UserController, it works, too.

If you type \ in your shell, shell will try to escape \, i.e.
echo Api\Admin\UserController will actually print ApiAdminUserController

This is a non-issue related to laravel

Was this page helpful?
0 / 5 - 0 ratings