Step 6 — List products from the database

Wire the catalog to SQLite so Ada sees real rows.

What you will learn

  • Read with table('products')->all()
  • Return rows inside the Moonlight envelope
Before you start
  • Step 5products table exists

Update listAction

protected function listAction(Arrayable $data): ApiResponse
{
    $products = table('products')->all();
    return response(0, 'OK', ['products' => $products]);
}

Verify

curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -d '{"service":"product","action":"list"}'

If you seeded in Step 5, you should see the mug and sticker pack. More query patterns: Making queries.

Common mistakes

  • Still seeing hard-coded data — save the file and confirm you removed the PHP array
  • Empty list — re-run seed inserts or migrate if the SQLite file was deleted