Skip to content

Commit 3c14653

Browse files
committed
config
1 parent b3201c2 commit 3c14653

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

config/groupable.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
*/
99
'models' => [
1010
'group' => [
11-
'key' => Yuges\Package\Enums\KeyType::BigInteger,
11+
'key' => [
12+
'has' => true,
13+
'type' => Yuges\Package\Enums\KeyType::BigInteger
14+
],
1215
'table' => 'groups',
1316
'class' => Yuges\Groupable\Models\Group::class,
1417
'observer' => Yuges\Groupable\Observers\GroupObserver::class,
1518
],
1619
'groupable' => [
1720
'table' => 'groupables',
18-
'key' => Yuges\Package\Enums\KeyType::BigInteger,
21+
'key' => [
22+
'has' => false,
23+
'type' => Yuges\Package\Enums\KeyType::BigInteger
24+
],
1925
'class' => Yuges\Groupable\Models\Groupable::class,
2026
'allowed' => [
2127
'classes' => [
@@ -28,7 +34,10 @@
2834
'observer' => Yuges\Groupable\Observers\GroupableObserver::class,
2935
],
3036
'grouperator' => [
31-
'key' => Yuges\Package\Enums\KeyType::BigInteger,
37+
'key' => [
38+
'has' => true,
39+
'type' => Yuges\Package\Enums\KeyType::BigInteger
40+
],
3241
'default' => [
3342
'class' => \App\Models\User::class,
3443
],

database/migrations/000_create_groups_table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public function up(): void
2121
}
2222

2323
Schema::create($this->table, function (Blueprint $table) {
24-
$table->key(Config::getGroupKeyType(KeyType::BigInteger));
24+
if (Config::getGroupKeyHas(true)) {
25+
$table->key(Config::getGroupKeyType(KeyType::BigInteger));
26+
}
2527

2628
Config::getPermissionsAnonymous(false)
2729
? $table->nullableKeyMorphs(

database/migrations/001_create_groupables_table.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public function up(): void
2222
}
2323

2424
Schema::create($this->table, function (Blueprint $table) {
25+
if (Config::getGroupableKeyHas(false)) {
26+
$table->key(Config::getGroupableKeyType(KeyType::BigInteger));
27+
}
28+
2529
$table
2630
->foreignIdFor(Config::getGroupClass(Group::class))
2731
->constrained()

src/Config/Config.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ public static function getGroupClass(mixed $default = null): string
2929
return self::get('models.group.class', $default);
3030
}
3131

32+
public static function getGroupKeyHas(mixed $default = null): bool
33+
{
34+
return self::get('models.group.key.has', $default);
35+
}
36+
3237
public static function getGroupKeyType(mixed $default = null): KeyType
3338
{
34-
return self::get('models.group.key', $default);
39+
return self::get('models.group.key.type', $default);
3540
}
3641

3742
/** @return class-string<GroupObserver> */
@@ -51,9 +56,14 @@ public static function getGroupableClass(mixed $default = null): string
5156
return self::get('models.groupable.class', $default);
5257
}
5358

59+
public static function getGroupableKeyHas(mixed $default = null): bool
60+
{
61+
return self::get('models.groupable.key.has', $default);
62+
}
63+
5464
public static function getGroupableKeyType(mixed $default = null): KeyType
5565
{
56-
return self::get('models.groupable.key', $default);
66+
return self::get('models.groupable.key.type', $default);
5767
}
5868

5969
public static function getGroupableRelationName(mixed $default = null): string
@@ -75,9 +85,14 @@ public static function getGroupableObserverClass(mixed $default = null): string
7585
return self::get('models.groupable.observer', $default);
7686
}
7787

88+
public static function getGrouperatorKeyHas(mixed $default = null): bool
89+
{
90+
return self::get('models.grouperator.key.has', $default);
91+
}
92+
7893
public static function getGrouperatorKeyType(mixed $default = null): KeyType
7994
{
80-
return self::get('models.grouperator.key', $default);
95+
return self::get('models.grouperator.key.type', $default);
8196
}
8297

8398
public static function getGrouperatorRelationName(mixed $default = null): string

0 commit comments

Comments
 (0)