首页 > 解决方案 > 注册表类型

问题描述

我正在尝试修改我的注册表以包含一个类型(餐厅或消费者)。我需要一个复选框,一旦选中将表明该帐户应该是餐厅。(未选中 = 消费者)。

我研究过盖茨,但这并不是我想要的。我的想法是在用户迁移中创建一个布尔属性。

播种机

public function run() {
    DB::table('users')->insert([
    'name' => "admin",
    'email' => 'admin@test.com',
    'password' => bcrypt('admin'),
    // 'type' => true
    ]);
}   

移民

Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        // $table->boolean('type');
        $table->rememberToken();
        $table->timestamps();
    });

在用户选中该框后,我希望餐厅用户能够编辑某些属性。消费者没有权限,只有查看权限。

标签: phplaravel

解决方案


你可以这样

Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->boolean('type')->default(0);
        $table->rememberToken();
        $table->timestamps();
    });

然后你可以运行迁移

public function run() {
    DB::table('users')->insert([
    'name' => "admin",
    'email' => 'admin@test.com',
    'password' => bcrypt('admin'),
    'type' => 1
    ]);
}  

推荐阅读