简体   繁体   English

Laravel Composer laravel 新命令

[英]Laravel Composer laravel new command

I'm trying to set laravel new command, but it is showing error like that.我正在尝试设置 laravel 新命令,但它显示这样的错误。

I have laravel file inside /.composer/vendor/bin我在/.composer/vendor/bin中有 laravel 文件

在此处输入图像描述

在此处输入图像描述

how can I solve this我该如何解决这个问题

If you're trying to create new Laravel project you can use command:如果您尝试创建新的 Laravel 项目,您可以使用命令:

composer create-project --prefer-dist laravel/laravel my-new-project

instead of installer.而不是安装程序。

On your screenshot it says that Laravel Installer is already installed so it has nothing to install or update.在您的屏幕截图上,它显示 Laravel 安装程序已安装,因此无需安装或更新。 So you might want to run command laravel new blog in fresh new empty directory and it may be working already.因此,您可能想在新的空目录中运行命令laravel new blog ,它可能已经在工作了。

If you're trying to create new console command in Laravel project and you want this command to be accessible from console and it could be something like php artisan my-command:run you can do the following below.如果您尝试在 Laravel 项目中创建新的控制台命令,并且您希望可以从控制台访问此命令,它可能类似于php artisan my-command:run ,您可以执行以下操作。

To do so you might want to generate new command executing this Laravel command from root directory of your project:为此,您可能希望从项目的根目录生成执行此 Laravel 命令的新命令:

php artisan make:command MyCommand

This command above is going to create new class under App\Console\Commands called MyCommand and it will be ready for customizing.上面的这个命令将在名为MyCommandApp\Console\Commands下创建新的 class,并且可以进行自定义。 You can change property protected $signature = 'my-command:run';您可以更改protected $signature = 'my-command:run'; and then when you run php artisan my-command:run from root directory of the project this command is going to run App\Console\Commands\MyCommand::handle() method and everything inside it will be executed.然后当您从项目的根目录运行php artisan my-command:run时,该命令将运行App\Console\Commands\MyCommand::handle()方法,其中的所有内容都将被执行。 So you can edit the method and achieve there what you want and the command will be ready.所以你可以编辑方法并在那里实现你想要的,命令就准备好了。

For details you can refer to this doc: https://laravel.com/docs/7.x/artisan有关详细信息,您可以参考此文档: https://laravel.com/docs/7.x/artisan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM