---
title: "Products & categories — Shops for Laravel | Roundly"
description: "Create products and categories, attach categories, schedule publishing and store names and descriptions in several languages."
url: https://roundly-consulting.com/open-source/docs/shops-for-laravel/catalog
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Shops for Laravel](https://roundly-consulting.com/open-source/docs/shops-for-laravel.md)

# Products & categories

Products and categories belong to an optional shop, generate a URL slug from their name and use it as the route key. Every product gets one default variant when it is created, and $product->price reads the default (lowest-position) variant’s price:

```php
use RoundlyConsulting\Shops\Products\Category;
use RoundlyConsulting\Shops\Products\Product;

$category = Category::create(['name' => 'Beverages', 'published_at' => now()]);
// $category->slug === 'beverages'

$product = Product::create(['name' => 'Sparkling Water', 'published_at' => now()]);
$product->categories()->attach($category);   // many-to-many, pivot with timestamps

$product->price;   // RoundlyConsulting\Money\Money — proxied from the default variant
```

## Relations at a glance

```php
$product->variants();          // HasMany<ProductVariant>
$product->defaultVariant();    // HasOne<ProductVariant> — lowest position
$product->options();           // HasMany<ProductOption>, ordered by position
$product->categories();        // BelongsToMany<Category>
$product->shop();              // BelongsTo — the configured tenant model
$product->variantFor([$id]);   // ?ProductVariant matching exactly these option-value ids
```

## Publishing

Products and categories share the HasPublishing concern, driven by a nullable published\_at — publish now, schedule for later, or keep a draft:

```php
Product::query()->published();     // published_at set and not in the future
Product::query()->unpublished();   // no published_at, or scheduled for later
Product::query()->forShop($shop)->published()->get();

$product->isPublished();           // bool

$product->update(['published_at' => now()->addWeek()]);   // schedule
$product->update(['published_at' => null]);               // back to draft

Category::query()->published()->get();                   // categories publish the same way
```

## Translations

name, slug and description are translatable, stored as native per-locale JSON. Reads return the current locale’s value, falling back to shops.locales.fallback; a plain-string write is stored under the current locale, so single-language stores need no extra work:

```php
$product->setTranslation('name', 'en', 'Sparkling Water');
$product->setTranslation('name', 'sk', 'Perlivá voda');
$product->save();

app()->setLocale('sk');
$product->name;                          // "Perlivá voda"
$product->getTranslation('name', 'en');  // "Sparkling Water"
$product->getTranslations('name');       // ['en' => 'Sparkling Water', 'sk' => 'Perlivá voda']

// A plain string is stored under the current locale:
$product->update(['description' => 'Naturally carbonated.']);

// Or set several locales at once:
Product::create(['name' => ['en' => 'Chair', 'sk' => 'Stolička']]);
```

Slugs are generated per locale from the name’s translations — see Slugs & URLs. Shop names translate the same way.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/shops-for-laravel.md)
