Skip to content

Commit ad4d964

Browse files
committed
Add shared seed company resolver concern
1 parent 1679656 commit ad4d964

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Fleetbase\Seeders\Concerns;
4+
5+
use Fleetbase\Models\Company;
6+
7+
trait ResolvesSeedCompany
8+
{
9+
protected function resolveSeedCompany(?string $fallbackUuidEnv = null, ?string $fallbackPublicIdEnv = null): ?Company
10+
{
11+
$companyUuid = env('SEED_COMPANY_UUID') ?: ($fallbackUuidEnv ? env($fallbackUuidEnv) : null);
12+
$companyPublicId = env('SEED_COMPANY_PUBLIC_ID') ?: ($fallbackPublicIdEnv ? env($fallbackPublicIdEnv) : null);
13+
14+
if ($companyUuid) {
15+
return Company::where('uuid', $companyUuid)->first();
16+
}
17+
18+
if ($companyPublicId) {
19+
return Company::where('public_id', $companyPublicId)->first();
20+
}
21+
22+
return Company::query()->orderBy('created_at')->first();
23+
}
24+
}

0 commit comments

Comments
 (0)