如何使用命令行界面(CLI)重命名 Laravel 控制器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41223078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:57:31  来源:igfitidea点击:

How can i rename laravel controller with command line interface(CLI)?

phplaravelcontroller

提问by Roni

I created controller which name is Homebut I want rename it with HomeController. Is it possible in laravel?

我创建了名称为的控制器,Home但我想用HomeController. 在laravel中可能吗?

Example:

例子:

class Home extends Controller { }

I Want to rename it like

我想重命名它

class HomeController extends Controller { }

I Want to do it with CLI.

我想用 CLI 来做。

回答by Komal

You have to do it manually, there is no any command available to updated controller name.

您必须手动执行此操作,没有任何命令可用于更新的控制器名称。

回答by KirtJ

forget CLIwhy not try rename the controller using 'AS'

忘记 CLI为什么不尝试使用“ AS”重命名控制器

use app\MyController as MyControl;

回答by Bara' ayyash

You can assess the file using nanocommand or vi, it depends on your machine. it basically an editor the enable you to change the content of the file.

您可以使用nanocommand 或来评估文件vi,这取决于您的机器。它基本上是一个编辑器,使您能够更改文件的内容。

回答by Md. Harun Or Rashid

Make a new Controller with the new Name.

使用新名称创建一个新控制器。

php artisan make:controller NewController

or 

php artisan make:controller NewController --resource

//if it is a resource controller

Now copy all contents from Old Controller to NewController.

现在将所有内容从旧控制器复制到新控制器。

Then edit all routes (in web.php) to that Controller.

然后编辑到该控制器的所有路由(在 web.php 中)。