首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >生成Artisan命令,而不是"php artisan serve“

生成Artisan命令,而不是"php artisan serve“
EN

Stack Overflow用户
提问于 2019-08-21 08:03:07
回答 1查看 6.6K关注 0票数 5

我想做个化名

php artisan go

而不是

php artisan serve

我会感激任何其他的想法:-) .I也读了这个链接并搜索了很多,但是它不是那么清楚,其他的问题是关于制作class.env文件等等。

提前感谢

更新这个问题不是的重复,因为它不包含调用php artisan本身。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-21 08:09:34

使用以下方法创建命令:

代码语言:javascript
代码运行次数:0
运行
复制
php artisan make:command GoCommand

在类中添加以下内容:

代码语言:javascript
代码运行次数:0
运行
复制
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\ConsoleOutput;

class GoCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'go';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $output = new ConsoleOutput;
        $output->writeln("Laravel development server started: <http://127.0.0.1:8000>");
        Artisan::call('serve');
        Artisan::output();
    }
}

使用以下命令:

代码语言:javascript
代码运行次数:0
运行
复制
php artisan go

访问:http://127.0.0.1:8000/

并在控制台中看到输出。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57587040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档