get existing locale or create new one

This commit is contained in:
Annika Wolff 2020-03-24 10:58:20 +01:00
parent e6e84dfdf9
commit 8a2a84b1e6
1 changed files with 9 additions and 1 deletions

View File

@ -5,8 +5,16 @@ use Webkul\Core\Models\Locale;
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(Locale::class, function (Faker $faker, array $attributes) {
$languageCode = $faker->languageCode;
$locale = Locale::query()->firstWhere('code', $languageCode);
if ($locale !== null) {
return $locale->id;
}
return [
'code' => $faker->languageCode,
'code' => $languageCode,
'name' => $faker->country,
'direction' => 'ltr',
];