parent_id always show Null我想以此方式在用户迁移中使用parent_id
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->primary(['id', 'parent_id']);
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
如果是这样,我该如何从register.blade.php插入数据并在registercontroller中编辑代码。
$parentid =????;
$position = $data['position'];
$posid = getLastChildOfLR($parentid,$position);
答案 0 :(得分:0)
尝试一下:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('parent_id')->nullable(); // root user will have null parent_id
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
$table->foreign('parent_id')->references('id')->on('users')->onDelete('cascade'); // cascade delete children when deleting parent
});