小编Md.*_*Ali的帖子

检查Laravel迁移文件中是否存在列

我已经有了一个表名,table_one.现在我想再添加两列。到目前为止一切正常。但是在我的方法中,我想检查表中是否存在某列,例如dropIfExists('table').

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('table_one', function (Blueprint $table) {
        $table->string('column_one')->nullable();
        $table->string('column_two')->nullable();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('table_one', function (Blueprint $table) {
        // in here i want to check column_one and column_two exists or not
        $table->dropColumn('column_one');
        $table->dropColumn('column_two');
    });
}
Run Code Online (Sandbox Code Playgroud)

php sql laravel

6
推荐指数
2
解决办法
3512
查看次数

Json 中的最佳 API 响应格式

哪一个最适合 Rest API 响应?

  1. 在这里我返回一些带有实际数据的元信息。尽管我不确定他们是否需要使用这些元信息。
{
    "version": "1.0.0",
    "isError": false,
    "statusCode": 200,
    "message": "Permission Object",
    "data": {
        "id": 1,
        "name": "user create",
        "created_at": "2022-11-30T10:18:20.000000Z"
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 在第二个示例中,我仅返回相关数据。
{
    "id": 1,
    "name": "user create",
    "created_at": "2022-11-30T10:18:20.000000Z"
}
Run Code Online (Sandbox Code Playgroud)

如果还有其他更好的方法请给我建议。

api rest json api-design

0
推荐指数
1
解决办法
2976
查看次数

标签 统计

api ×1

api-design ×1

json ×1

laravel ×1

php ×1

rest ×1

sql ×1