Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 拉维集状态列_Laravel_Migration_Constants - Fatal编程技术网

Laravel 拉维集状态列

Laravel 拉维集状态列,laravel,migration,constants,Laravel,Migration,Constants,我想在我的胶片表中添加一个名为status的新列,该列有两个选项active或inactive,我想在默认情况下将DB中的所有当前胶片设置为active 我的第一个想法是创建一个将状态设置为常量的库文件,以防我决定添加更多。e、 g const active = 1; const inactive = 2; 然后我可以将该常量作为默认值传递到新列中吗 迁移文件 /** * Run the migrations. * * @return void */ public function u

我想在我的胶片表中添加一个名为
status
的新列,该列有两个选项
active
inactive
,我想在默认情况下将DB中的所有当前胶片设置为active

我的第一个想法是创建一个将状态设置为常量的库文件,以防我决定添加更多。e、 g

const active = 1;
const inactive = 2;
然后我可以将该常量作为默认值传递到新列中吗

迁移文件

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('films', function (Blueprint $table) {
        $table->string('status')->default(\App\Library\Status::active);
    });
}

一些帮助将非常有用

将数据类型设置为
枚举
,并将值设置为
活动
非活动
,使用默认值
活动
它将自动设置
活动
,您不需要按常量传递它

$table->enum('status',['active','deactive'])->default('active');

啊,有趣!如果您想在状态列表中添加更多,您是否只需将它们添加到数组括号中?当我开始添加逻辑时,它会根据管理员是否暂停某个人使用这种方式仍然是理想的,或者您会使用const来更改状态?是的,如果您想添加更多状态,请将其添加到数组中。