GitHub Copilot 体验

作者: 温新

分类: 【Laravel】

阅读: 2175

时间: 2023-04-02 05:36:13

hi,我是温新,一名 PHPer

我没有 visa 卡,很多关于 AI 的东西都卡在这个地方了。

今天终于把 GitHub Copilot 搞好了。GitHub Copilot 以插件的形式安装,可以在 vscode、phpstorm 等编辑器中进行安装。

现在使用自然语言来进行一个体验吧。

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('posts', function (Blueprint $table) {
            // 添加 title 字段,可以为空
            $table->string('title')->nullable();
            // add keywords column, can be null
            $table->string('keywords')->nullable();
            // 添加 description 字段,可以为空
            $table->string('description')->nullable();
            // 添加 content 字段,可以为空
            $table->text('content')->nullable();
            // 添加 author 字段,可以为空
            $table->string('author')->nullable();
            // 添加 source 字段,不为null,默认 0
            $table->string('source')->default(0);
            // 添加 hits 字段,不为null,默认 0
            $table->integer('hits')->default(0);
            // 添加 is_top 字段,不为null,默认 0
            $table->integer('is_top')->default(0);
            // add is_comment column, not null,default 0, comment '是否允许评论,0:不允许,1:允许'
            $table->integer('is_comment')->default(0)->comment('是否允许评论,0:不允许,1:允许');
            // 添加 status 字段,不为null,默认 0, comment '状态,0:未审核,1:已审核'
            $table->integer('status')->default(0)->comment('状态,0:未审核,1:已审核');
        });
    }
    
    public function down(): void
    {
        Schema::table('posts', function (Blueprint $table) {
        });
    }
};

这个案例中,我没有编写代码,那在写什么呢?**我在写注释。**注释写完之后,就会自动生成相关代码。

GitHub Copilot 可以根据这个表自动猜测所需要的字段。总体体验下来是很不错的。

请登录后再评论