php 无法执行 Laravel 工匠命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21994590/
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
Unable to execute Laravel artisan commands
提问by Severin
I just installed the latest version of Laravel and tried to run the following command from my Git Bash:
我刚刚安装了最新版本的 Laravel,并尝试从我的 Git Bash 运行以下命令:
php artisan migrate:make create_users_table --table=users --create
This triggers the following error:
这会触发以下错误:
Could not open input file: artisan
I have tried a number of things I found here on this site, but nothing seems to work. Any suggestions on how to make it work?
我已经尝试了很多我在这个网站上找到的东西,但似乎没有任何效果。有关如何使其工作的任何建议?
回答by totymedli
tl;dr
tl;博士
Run composer installin your project's root folder.
运行composer install在你的项目的根文件夹。
Explanation
解释
This happens when you create a project by downloading and extracting the laravel/laravelrepo from GitHub, not by using the Composer command:
当您通过从 GitHub下载并提取laravel/laravel 存储库而不是使用 Composer 命令创建项目时,会发生这种情况:
composer create-project laravel/laravel your-project-name
In this case the dependencies are not installed, so the vendorfolder that contains Artisan doesn't exist. Running composer installin your project's root folder will install the dependencies vendorfolder.
在这种情况下,未安装依赖项,因此vendor包含 Artisan的文件夹不存在。composer install在项目的根文件夹中运行将安装依赖项vendor文件夹。
For more, see my other answer on how to install Artisan.
有关更多信息,请参阅我关于如何安装 Artisan 的其他答案。
Side note
边注
This is independent from your problem but your Artisan command is a bit deficient. You forgot =users(the table name) from the end. Also if you create a table you dont have to specify the table name again with the --tableoption so this command would be enough:
这与您的问题无关,但您的 Artisan 命令有点不足。你=users从最后忘记了(表名)。此外,如果您创建一个表,则不必再次使用该--table选项指定表名,因此此命令就足够了:
php artisan migrate:make create_users_table --create=users
回答by Francisco Corrales Morales
You don't have artisan. There are two reasons:
你没有工匠。有两个原因:
To be able to run
php artisan <command>you must be in your project folder, so first move to that folder using thecdcommand, then you can execute the command.You haven't created a Laravelproject in that folder. You must create one with Composer.
为了能够运行
php artisan <command>你必须在你的项目文件夹中,所以首先使用cd命令移动到那个文件夹,然后你可以执行命令。您尚未在该文件夹中创建Laravel项目。您必须使用 Composer 创建一个。
回答by Stranger
Laravel needs the PHP version 5.5.9. If you have some lower version, you may not get anything executed and it may not throw any error based on you settings.
Laravel 需要 PHP 5.5.9 版本。如果您有一些较低版本,您可能无法执行任何操作,并且可能不会根据您的设置抛出任何错误。
回答by Miroslav Trninic
In your root directory you have artisan.phpfile which is internally triggering Illuminate\Console\Application::start($app);
在你的根目录中有artisan.php文件,它在内部触发Illuminate\Console\Application::start($app);
So follow that path and see what is happening. Do you have any output when you run php artisan? That error is usually shown when artisan is not in your path (current directory).
所以沿着这条路走,看看发生了什么。运行php artisan时有任何输出吗?当工匠不在您的路径(当前目录)中时,通常会显示该错误。

