forked from leeovery/claude-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppServiceProvider.php
More file actions
37 lines (31 loc) · 1.07 KB
/
AppServiceProvider.php
File metadata and controls
37 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->registerModelFactoryResolver();
}
/**
* Register factory resolver for Data objects.
*
* This allows Factory::factoryForModel() to resolve Data test factories
* from the correct namespace (Database\Factories\Data\).
*
* Classes ending in 'Data' → Database\Factories\Data\{ClassName}Factory
* All other classes → Database\Factories\{ClassName}Factory
*/
private function registerModelFactoryResolver(): void
{
Factory::guessFactoryNamesUsing(function (string $modelName) {
if (str($modelName)->endsWith('Data')) {
return 'Database\Factories\Data\\'.Str::afterLast($modelName, '\\').'Factory';
}
return 'Database\Factories\\'.Str::afterLast($modelName, '\\').'Factory';
});
}
}