# Seed Patterns

## Translatable models
Use `translateOrNew()` per locale and save once.

```php
$model = Model::create([...]);
foreach (config('translatable.locales') as $locale) {
    $model->translateOrNew($locale)->name = $names[$locale];
}
$model->save();
```

## Media attachments (HasMedia)
If a model uses `HasMedia` with a media option (e.g., `logo`, `image`), seed a `media` record and pass its ID in the create payload, or update after create.

Recommended: reuse existing public assets (e.g., `public/assets/images/logo.png`) and store them under `storage/app/public/seeders`.

High-level steps:
1. Copy a file into `storage/app/public/seeders`.
2. Create a `media` record with `disk=public`, `path=seeders`, `name=<filename>`, `type=image`, `extension=png`.
3. For the target model, set the media ID in the request payload (or update after create and let the observer attach).

## First-or-create to avoid duplicates
```php
Model::firstOrCreate(
  ['unique_key' => $value],
  ['other' => 'attrs']
);
```

## Category and SubCategory lookup by translation
```php
$categoryId = CategoryTranslation::where('locale','en')
  ->where('name','Restaurants')
  ->value('category_id');
```
