> For the complete documentation index, see [llms.txt](https://vladimirkostikov.gitbook.io/laraboom/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vladimirkostikov.gitbook.io/laraboom/application-behavior/13-seeding-make.md).

# 13. Seeds and generators

## Resource seeds

Two ways:

1. An explicit `seeds(): Examples`
2. The `#[Seed(count: N)]` attribute when there are no explicit examples

### Examples and Sample

```php
use LaraBoom\Definition\Examples;
use function LaraBoom\Author\Examples;
use function LaraBoom\Author\Sample;

public function seeds(): Examples
{
    return Examples(
        Sample('Ada Lovelace', 'ada@demo.boom', 'password', 'First seed row.', 4500, 12, 'active', true),
        Sample('Grace Hopper', 'grace@demo.boom', 'password', 'Second seed row.', 12900, 8, 'active', false),
        Sample('Draft Kit', 'draft@demo.boom', 'password', 'Optional child example.', 0, 0, 'draft', false),
    );
}
```

The positional values in `Sample` match the order of fields in `fields()` (taking into account how the seeder maps the tuple). Money is written in the smallest units. `4500` is 45.00 RUB with the RUB currency.

### Commands

```bash
php boom seed                 # all resources that have seeds
php boom seed demos           # one resource
php boom seed --fresh         # reseed (careful with data)
php boom seed --status        # coverage: defined vs present in the database
```

`install --fresh` and `rebuild --force --seed` also run the seeds at the end of the chain.

## Why seeds in Demo

* there are rows on `/` and in `/api/demos` right away
* you can log in as `ada@demo.boom` / `password` (if the password is seeded into a Secret field as in Demo)
* feature tests rely on predictable data

Check the current password and Allow in the code if you have changed Demo.

## The make generator

```bash
php boom make Product title:string price:money --sync
php boom make Product --type=resource
php boom make Shop --type=route
php boom make Product --type=service
php boom make Product --type=job
php boom make Product --type=event
php boom make Product --type=mail
php boom make Product --type=notice
```

The default type is resource. With `--sync` it runs the schema sync for the new Migrate resource right away. `--force` overwrites the file.

Stubs are placed in the LaraBoom author style (colocated under Resources / Routes) rather than in Laravel folders like `app/Jobs`.

## Creating a Resource by hand

1. The `app/Resources/Product.php` file
2. `#[Migrate]`, `fields()`, and `#[Allow]` if needed
3. `php boom sync`
4. `php boom seed` or manual inserts through the shell
5. `php boom explain products`

## Creating a Path by hand

1. `app/Routes/Catalog.php` extends Path
2. methods with `#[Get]` / `#[Post]`
3. views in `web/views/...`
4. `php boom routes` to make sure the routes are visible

## A Service next to the entity

When a Resource method grows:

```
app/Resources/Product.php
app/Resources/Product/Service.php
```

The Path or the Resource calls the Service. We do not create a top level `app/Services`.

## New entity checklist

* [ ] Resource + Migrate + Allow
* [ ] sync with no drift
* [ ] seeds or a clear way to fill the dev database
* [ ] a Path, or `/api` is enough
* [ ] explain / openapi are up to date
* [ ] a test for the CRUD or the page

## Seeds and soft deletes / scopes

A `#[Scope]` like `hideArchived` affects `query()`. The seeder usually writes through the same query/create. Archived rows from Sample may be invisible in the index API even though they sit in the table. In Demo the third row with `status=draft` is visible because the scope only cuts `archived`.

Check `seed --status` and the raw SQL if it looks like seeding did not work while the row count in schema grows.

## Seed idempotency

A repeated `php boom seed` without `--fresh` depends on the seeder implementation (adding or skipping). For a clean state in dev:

```bash
php boom rebuild --force --seed
```

or `seed --fresh` on a single resource. Do not run `--fresh` in production with live data.

## Field generation in make

The fields arguments in the CLI (the `title:string`, `price:money` form) are shorthands for the Resource stub. After generating, still open the file and finish Allow, Scope and relations by hand. Make saves typing, it does not replace model design.

## The link with tests

In `DemoTest` the seeds are brought up like this:

```php
foreach ((new Demo)->resolvedSeeds() as $row) {
    (new Demo)->query()->create($row);
}
```

This way a feature test does not have to call the Artisan seed. For package tests the schema and seeds are set up by the package Testbench environment.

Next up is [Tooling and OpenAPI](/laraboom/quality/14-tooling.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://vladimirkostikov.gitbook.io/laraboom/application-behavior/13-seeding-make.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
