我如何从
更改我的控制器名称空间namespace App\Http\Controller\Folder\MyController
到
namespace Folder\MyController
im new using laravel 5.2
答案 0 :(得分:1)
您可以在composer.json文件中更改psr-4
。
"psr-4": {
"YourProject\\": "app/"
}
因此,您的命名空间将为namespace YourProject/Http/Controller
。不要忘记自动加载你的作曲家。我认为这是你在找。
答案 1 :(得分:0)
这是5.2工匠命令;
php artisan app:name MyApp
认为您之后需要运行php artisan dump-autoload
。
答案 2 :(得分:0)
您需要在控制器中添加它:
namespace App\Http\Controllers\Folder;
use App\Http\Controllers\Controller;
并在您的路线中添加此内容,
Route::group(['namespace'=>'Folder'], function () {
// place your MyController route here;
});
答案 3 :(得分:0)
试试这个:
1)运行php artisan app:name YourNamespace
2)将您的app文件夹重命名为YourNamespace
3)在你的bootstrap文件夹中创建一个名为application.php的文件
4)将其粘贴在那里
class Application extends Illuminate\Foundation\Application {
protected $appBasePath = 'app';
public function __construct($basePath = null)
{
$this->registerBaseBindings();
$this->registerBaseServiceProviders();
$this->registerCoreContainerAliases();
if ($basePath) $this->setBasePath($basePath);
}
public function setAppPath($path) {
// store the path in the class only
$this->appBasePath = $path;
// set the path in the container (using this class's path to reset it)
return app()->__set('path', $this->path());
}
/**
* Get the path to the application "app" directory.
*
* @return string
*/
public function path()
{
return $this->basePath.DIRECTORY_SEPARATOR.$this->appBasePath;
}
}
5)保存文件并打开app.php
6)并使用以下
// load our local application
require __DIR__.'/application.php';
// instaniate our application
$app = new \Application(
realpath(__DIR__.'/../')
);
// set the path to match the namespace
$app->setAppPath('YourNamespace');
7)保存你的app.php,就是这样
希望这对你有所帮助。