Skip to content

Commit dc00e0c

Browse files
committed
Comments
1 parent 479e882 commit dc00e0c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

config/turbo-laravel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
| Root Model Namespaces
2020
|--------------------------------------------------------------------------
2121
|
22-
| When generating the DOM ID for models, we need to strip out parts of the namespace, so we
23-
| can more accurate DOM IDs. If you happen to use a different convention for where you place
24-
| your models, please, add the model namespace prefixes here. We'll strip out the first one that
25-
| matches a "Str:startsWith()" check, so sort them from more specific to less specific.
22+
| When generating DOM IDs for models, we need to strip out the root namespaces from the model's FQCN. Please,
23+
| if you use non-conventional folder structures, make sure you add your custom namespaces to this list. The
24+
| first one that matches a "starts with" check will be used and removed from the model's FQCN for DOM IDs.
25+
|
2626
*/
2727
'models_namespace' => [
2828
'App\\Models\\',

src/NamesResolver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public static function resourceIdFor(Model $model, string $prefix = ""): string
8080

8181
private static function getModelWithoutRootNamespaces(Model $model): string
8282
{
83+
// We will attempt to strip out only the root namespace from the model's FQCN. For that, we will use
84+
// the configured namespaces, stripping out the first one that matches on a Str::startsWith check.
85+
// Namespaces are configurable. We'll default back to class_basename when no namespace matches.
86+
8387
$className = get_class($model);
8488

8589
foreach (config('turbo-laravel.models_namespace') as $rootNs) {
@@ -88,7 +92,6 @@ private static function getModelWithoutRootNamespaces(Model $model): string
8892
}
8993
}
9094

91-
// If none of the previous matchers work, we use the class_basename helper instead.
9295
return class_basename($model);
9396
}
9497
}

0 commit comments

Comments
 (0)