You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: document coupon constraints and pivot/FK conventions
Note the coupon creator FKs and the three scoping pivots' foreign-key and
unique rules in the schema doc, add migration/multi-select conventions to
AGENTS.md, and mark Coupons done in IMPLEMENTATION.md.
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: admin/AGENTS.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,6 +199,7 @@ When adding a new entity, build the files in this order, matching the existing f
199
199
- Select fields backed by an enum use `->options(SomeEnum::options())` and `->default(SomeEnum::CASE->value)`.
200
200
- Table text columns that can be long (headings, relation labels) use `->limit(30)->wrap()`.
201
201
- Enum-backed table columns render via `->getStateUsing(fn ($record) => $record->field->label())` and `->color(fn ($record) => $record->field->color())`.
202
+
- Manage many-to-many pivots with a relationship multi-select: `Select::make('products')->relationship('products', 'heading')->multiple()->searchable()->preload()` (see `CouponResource`). No separate resource for pure scoping pivots.
202
203
203
204
## Models
204
205
@@ -218,7 +219,9 @@ When adding a new entity, build the files in this order, matching the existing f
218
219
## Migrations
219
220
220
221
- Anonymous class style: `return new class extends Migration`.
221
-
- Use `$table->foreignIdFor(Model::class)` for foreign keys (add `->nullable()` when optional).
222
+
- Use `$table->foreignIdFor(Model::class)` for foreign keys (add `->nullable()` when optional). Chain `->constrained()->cascadeOnDelete()` / `->nullOnDelete()` / `->restrictOnDelete()` to add the real FK constraint with its delete rule.
223
+
- For a second FK to the same table, use a named column: `$table->foreignId('user_creator_id')->nullable()->constrained('users')->nullOnDelete()` (see `coupons`).
224
+
- Pivot tables add `$table->unique([...])` on the key pair and `->cascadeOnDelete()` on both FKs (see `coupon_product`).
222
225
- Default enum columns to a case value: `$table->unsignedTinyInteger('status')->default(ProductStatusEnum::PUBLISHED->value);`.
223
226
- Always implement `down()` with `Schema::dropIfExists(...)`.
0 commit comments