Output:
Chunk ID: 4b8c36
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1195
Output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentShipmentStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Events\OrderCancelled;
use App\Events\OrderPaid;
use App\Jobs\CancelUnpaidBankTransferOrders;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\StoreSettings;
use App\Services\OrderService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

/**
 * @return array{0: Order, 1: ProductVariant}
 */
function bankTransferOrder(bool $digital = false, int $ageDays = 1): array
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    StoreSettings::query()->create([
        'store_id' => $store->getKey(),
        'settings_json' => ['bank_transfer_cancel_days' => 7],
    ]);

    $product = Product::factory()->withDefaultVariant(2500)->create(['store_id' => $store->getKey()]);
    $variant = ProductVariant::withoutGlobalScopes()->where('product_id', $product->getKey())->firstOrFail();
    $variant->forceFill([
        'requires_shipping' => ! $digital,
        'weight_g' => $digital ? 0 : $variant->weight_g,
    ])->save();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 10,
            'quantity_reserved' => 2,
        ]);

    $order = Order::factory()->bankTransfer()->create([
        'store_id' => $store->getKey(),
        'payment_method' => PaymentMethod::BankTransfer,
        'status' => OrderStatus::Pending,
        'financial_status' => FinancialStatus::Pending,
        'placed_at' => now()->subDays($ageDays),
        'subtotal_amount' => 5000,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => 5000,
    ]);
    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'quantity' => 2,
        'unit_price_amount' => 2500,
        'total_amount' => 5000,
    ]);
    Payment::factory()->bankTransfer()->create([
        'order_id' => $order->getKey(),
        'amount' => 5000,
    ]);

    return [$order, $variant];
}

test('confirming bank transfer payment captures payment and commits reserved inventory', function () {
    [$order, $variant] = bankTransferOrder();

    Event::fake();

    $paidOrder = app(OrderService::class)->confirmBankTransferPayment($order);
    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($paidOrder->status)->toBe(OrderStatus::Paid)
        ->and($paidOrder->financial_status)->toBe(FinancialStatus::Paid)
        ->and($paidOrder->payments->first()->status)->toBe(PaymentStatus::Captured)
        ->and($inventory->quantity_on_hand)->toBe(8)
        ->and($inventory->quantity_reserved)->toBe(0);

    Event::assertDispatched(OrderPaid::class);
});

test('confirming digital bank transfer payment auto-fulfills the order', function () {
    [$order] = bankTransferOrder(digital: true);

    $paidOrder = app(OrderService::class)->confirmBankTransferPayment($order);

    expect($paidOrder->status)->toBe(OrderStatus::Fulfilled)
        ->and($paidOrder->fulfillment_status)->toBe(FulfillmentStatus::Fulfilled)
        ->and($paidOrder->fulfillments)->toHaveCount(1)
        ->and($paidOrder->fulfillments->first()->status)->toBe(FulfillmentShipmentStatus::Delivered);
});

test('cancel job voids stale bank transfer orders and releases reservations', function () {
    [$oldOrder, $oldVariant] = bankTransferOrder(ageDays: 8);
    [$newOrder, $newVariant] = bankTransferOrder(ageDays: 2);

    Event::fake();

    (new CancelUnpaidBankTransferOrders)->handle(app(OrderService::class));

    $oldInventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $oldVariant->getKey())->firstOrFail();
    $newInventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $newVariant->getKey())->firstOrFail();

    expect($oldOrder->refresh()->status)->toBe(OrderStatus::Cancelled)
        ->and($oldOrder->financial_status)->toBe(FinancialStatus::Voided)
        ->and($oldOrder->payments()->first()?->status)->toBe(PaymentStatus::Failed)
        ->and($oldInventory->quantity_on_hand)->toBe(10)
        ->and($oldInventory->quantity_reserved)->toBe(0)
        ->and($newOrder->refresh()->status)->toBe(OrderStatus::Pending)
        ->and($newInventory->quantity_reserved)->toBe(2);

    Event::assertDispatched(OrderCancelled::class);
});


sed -n '1,260p' tests/Feature/Orders/RefundServiceTest.php

RefundServiceTest.php

<?php

use App\Enums\FinancialStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentStatus;
use App\Enums\RefundStatus;
use App\Events\OrderRefunded;
use App\Exceptions\InvalidRefundOperationException;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Services\RefundService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

/**
 * @return array{0: Order, 1: OrderLine, 2: ProductVariant}
 */
function refundServiceOrder(int $quantity = 2, int $unitPrice = 5000): array
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    $product = Product::factory()
        ->withDefaultVariant($unitPrice)
        ->create(['store_id' => $store->getKey()]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 8,
            'quantity_reserved' => 0,
        ]);

    $total = $quantity * $unitPrice;
    $order = Order::factory()->paid()->create([
        'store_id' => $store->getKey(),
        'subtotal_amount' => $total,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => $total,
    ]);
    $line = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'quantity' => $quantity,
        'unit_price_amount' => $unitPrice,
        'total_amount' => $total,
    ]);

    Payment::factory()->create([
        'order_id' => $order->getKey(),
        'status' => PaymentStatus::Captured,
        'amount' => $total,
    ]);

    return [$order, $line, $variant];
}

test('refund service processes a partial line refund and restocks inventory', function () {
    [$order, $line, $variant] = refundServiceOrder();

    Event::fake();

    $refund = app(RefundService::class)->process($order, [
        'lines' => [$line->getKey() => 1],
        'reason' => 'Customer return',
        'restock' => true,
    ]);

    expect($refund->amount)->toBe(5000)
        ->and($refund->status)->toBe(RefundStatus::Processed)
        ->and($refund->provider_refund_id)->toStartWith('mock_refund_')
        ->and($order->refresh()->status)->toBe(OrderStatus::Paid)
        ->and($order->financial_status)->toBe(FinancialStatus::PartiallyRefunded)
        ->and($order->payments()->first()?->status)->toBe(PaymentStatus::Captured)
        ->and(InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->first()?->quantity_on_hand)->toBe(9);

    Event::assertDispatched(OrderRefunded::class, fn (OrderRefunded $event): bool => $event->refund->is($refund));
});

test('refund service marks order and payment refunded when the full amount is refunded', function () {
    [$order] = refundServiceOrder();

    $refund = app(RefundService::class)->process($order);

    expect($refund->amount)->toBe(10000)
        ->and($order->refresh()->status)->toBe(OrderStatus::Refunded)
        ->and($order->financial_status)->toBe(FinancialStatus::Refunded)
        ->and($order->payments()->first()?->status)->toBe(PaymentStatus::Refunded);
});

test('refund service rejects over-refunds and orders without captured payments', function () {
    [$order] = refundServiceOrder();

    expect(fn () => app(RefundService::class)->process($order, ['amount' => 10001]))
        ->toThrow(InvalidRefundOperationException::class);

    $order->payments()->update(['status' => PaymentStatus::Pending]);

    expect(fn () => app(RefundService::class)->process($order, ['amount' => 500]))
        ->toThrow(InvalidRefundOperationException::class);
});


sed -n '1,260p' tests/Feature/Orders/FulfillmentServiceTest.php

FulfillmentServiceTest.php

<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentShipmentStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Events\FulfillmentCreated;
use App\Events\FulfillmentDelivered;
use App\Events\FulfillmentShipped;
use App\Exceptions\InvalidFulfillmentOperationException;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Services\FulfillmentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

/**
 * @return array{0: Order, 1: OrderLine, 2: OrderLine}
 */
function fulfillmentServiceOrder(FinancialStatus $financialStatus = FinancialStatus::Paid): array
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    $firstProduct = Product::factory()->withDefaultVariant(2500)->create(['store_id' => $store->getKey()]);
    $secondProduct = Product::factory()->withDefaultVariant(1500)->create(['store_id' => $store->getKey()]);
    $firstVariant = ProductVariant::withoutGlobalScopes()->where('product_id', $firstProduct->getKey())->firstOrFail();
    $secondVariant = ProductVariant::withoutGlobalScopes()->where('product_id', $secondProduct->getKey())->firstOrFail();

    $order = Order::factory()->paid()->create([
        'store_id' => $store->getKey(),
        'financial_status' => $financialStatus,
        'status' => $financialStatus === FinancialStatus::Pending ? OrderStatus::Pending : OrderStatus::Paid,
    ]);
    $firstLine = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $firstProduct->getKey(),
        'variant_id' => $firstVariant->getKey(),
        'quantity' => 2,
        'unit_price_amount' => 2500,
        'total_amount' => 5000,
    ]);
    $secondLine = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $secondProduct->getKey(),
        'variant_id' => $secondVariant->getKey(),
        'quantity' => 1,
        'unit_price_amount' => 1500,
        'total_amount' => 1500,
    ]);

    return [$order, $firstLine, $secondLine];
}

test('fulfillment service blocks fulfillment until payment is confirmed', function () {
    [$order, $line] = fulfillmentServiceOrder(FinancialStatus::Pending);

    expect(fn () => app(FulfillmentService::class)->create($order, [$line->getKey() => 1]))
        ->toThrow(InvalidFulfillmentOperationException::class);
});

test('fulfillment service creates partial and complete fulfillments', function () {
    [$order, $firstLine, $secondLine] = fulfillmentServiceOrder();

    Event::fake();

    $firstFulfillment = app(FulfillmentService::class)->create($order, [
        $firstLine->getKey() => 2,
    ], [
        'tracking_company' => 'DHL',
        'tracking_number' => 'DHL123',
    ]);

    expect($firstFulfillment->status)->toBe(FulfillmentShipmentStatus::Pending)
        ->and($order->refresh()->fulfillment_status)->toBe(FulfillmentStatus::Partial)
        ->and($order->status)->toBe(OrderStatus::Paid);

    $secondFulfillment = app(FulfillmentService::class)->create($order, [
        $secondLine->getKey() => 1,
    ]);

    expect($secondFulfillment->lines)->toHaveCount(1)
        ->and($order->refresh()->fulfillment_status)->toBe(FulfillmentStatus::Fulfilled)
        ->and($order->status)->toBe(OrderStatus::Fulfilled);

    Event::assertDispatched(FulfillmentCreated::class, 2);
});

test('fulfillment service rejects over-fulfillment and invalid transitions', function () {
    [$order, $line] = fulfillmentServiceOrder();
    $fulfillment = app(FulfillmentService::class)->create($order, [$line->getKey() => 1]);

    expect(fn () => app(FulfillmentService::class)->create($order, [$line->getKey() => 2]))
        ->toThrow(InvalidFulfillmentOperationException::class);

    expect(fn () => app(FulfillmentService::class)->markDelivered($fulfillment))
        ->toThrow(InvalidFulfillmentOperationException::class);
});

test('fulfillment service marks shipments as shipped and delivered', function () {
    [$order, $line] = fulfillmentServiceOrder();
    $fulfillment = app(FulfillmentService::class)->create($order, [$line->getKey() => 1]);

    Event::fake();

    $shipped = app(FulfillmentService::class)->markShipped($fulfillment);
    $delivered = app(FulfillmentService::class)->markDelivered($shipped);

    expect($shipped->status)->toBe(FulfillmentShipmentStatus::Shipped)
        ->and($shipped->shipped_at)->not->toBeNull()
        ->and($delivered->status)->toBe(FulfillmentShipmentStatus::Delivered)
        ->and($delivered->delivered_at)->not->toBeNull();

    Event::assertDispatched(FulfillmentShipped::class);
    Event::assertDispatched(FulfillmentDelivered::class);
});


Output:
Chunk ID: 0ac35c
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1200
Output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentShipmentStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Events\FulfillmentCreated;
use App\Events\FulfillmentDelivered;
use App\Events\FulfillmentShipped;
use App\Exceptions\InvalidFulfillmentOperationException;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Services\FulfillmentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

/**
 * @return array{0: Order, 1: OrderLine, 2: OrderLine}
 */
function fulfillmentServiceOrder(FinancialStatus $financialStatus = FinancialStatus::Paid): array
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    $firstProduct = Product::factory()->withDefaultVariant(2500)->create(['store_id' => $store->getKey()]);
    $secondProduct = Product::factory()->withDefaultVariant(1500)->create(['store_id' => $store->getKey()]);
    $firstVariant = ProductVariant::withoutGlobalScopes()->where('product_id', $firstProduct->getKey())->firstOrFail();
    $secondVariant = ProductVariant::withoutGlobalScopes()->where('product_id', $secondProduct->getKey())->firstOrFail();

    $order = Order::factory()->paid()->create([
        'store_id' => $store->getKey(),
        'financial_status' => $financialStatus,
        'status' => $financialStatus === FinancialStatus::Pending ? OrderStatus::Pending : OrderStatus::Paid,
    ]);
    $firstLine = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $firstProduct->getKey(),
        'variant_id' => $firstVariant->getKey(),
        'quantity' => 2,
        'unit_price_amount' => 2500,
        'total_amount' => 5000,
    ]);
    $secondLine = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $secondProduct->getKey(),
        'variant_id' => $secondVariant->getKey(),
        'quantity' => 1,
        'unit_price_amount' => 1500,
        'total_amount' => 1500,
    ]);

    return [$order, $firstLine, $secondLine];
}

test('fulfillment service blocks fulfillment until payment is confirmed', function () {
    [$order, $line] = fulfillmentServiceOrder(FinancialStatus::Pending);

    expect(fn () => app(FulfillmentService::class)->create($order, [$line->getKey() => 1]))
        ->toThrow(InvalidFulfillmentOperationException::class);
});

test('fulfillment service creates partial and complete fulfillments', function () {
    [$order, $firstLine, $secondLine] = fulfillmentServiceOrder();

    Event::fake();

    $firstFulfillment = app(FulfillmentService::class)->create($order, [
        $firstLine->getKey() => 2,
    ], [
        'tracking_company' => 'DHL',
        'tracking_number' => 'DHL123',
    ]);

    expect($firstFulfillment->status)->toBe(FulfillmentShipmentStatus::Pending)
        ->and($order->refresh()->fulfillment_status)->toBe(FulfillmentStatus::Partial)
        ->and($order->status)->toBe(OrderStatus::Paid);

    $secondFulfillment = app(FulfillmentService::class)->create($order, [
        $secondLine->getKey() => 1,
    ]);

    expect($secondFulfillment->lines)->toHaveCount(1)
        ->and($order->refresh()->fulfillment_status)->toBe(FulfillmentStatus::Fulfilled)
        ->and($order->status)->toBe(OrderStatus::Fulfilled);

    Event::assertDispatched(FulfillmentCreated::class, 2);
});

test('fulfillment service rejects over-fulfillment and invalid transitions', function () {
    [$order, $line] = fulfillmentServiceOrder();
    $fulfillment = app(FulfillmentService::class)->create($order, [$line->getKey() => 1]);

    expect(fn () => app(FulfillmentService::class)->create($order, [$line->getKey() => 2]))
        ->toThrow(InvalidFulfillmentOperationException::class);

    expect(fn () => app(FulfillmentService::class)->markDelivered($fulfillment))
        ->toThrow(InvalidFulfillmentOperationException::class);
});

test('fulfillment service marks shipments as shipped and delivered', function () {
    [$order, $line] = fulfillmentServiceOrder();
    $fulfillment = app(FulfillmentService::class)->create($order, [$line->getKey() => 1]);

    Event::fake();

    $shipped = app(FulfillmentService::class)->markShipped($fulfillment);
    $delivered = app(FulfillmentService::class)->markDelivered($shipped);

    expect($shipped->status)->toBe(FulfillmentShipmentStatus::Shipped)
        ->and($shipped->shipped_at)->not->toBeNull()
        ->and($delivered->status)->toBe(FulfillmentShipmentStatus::Delivered)
        ->and($delivered->delivered_at)->not->toBeNull();

    Event::assertDispatched(FulfillmentShipped::class);
    Event::assertDispatched(FulfillmentDelivered::class);
});


Output:
Chunk ID: 1763f0
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 986
Output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentStatus;
use App\Enums\RefundStatus;
use App\Events\OrderRefunded;
use App\Exceptions\InvalidRefundOperationException;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Services\RefundService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

/**
 * @return array{0: Order, 1: OrderLine, 2: ProductVariant}
 */
function refundServiceOrder(int $quantity = 2, int $unitPrice = 5000): array
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    $product = Product::factory()
        ->withDefaultVariant($unitPrice)
        ->create(['store_id' => $store->getKey()]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 8,
            'quantity_reserved' => 0,
        ]);

    $total = $quantity * $unitPrice;
    $order = Order::factory()->paid()->create([
        'store_id' => $store->getKey(),
        'subtotal_amount' => $total,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => $total,
    ]);
    $line = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'quantity' => $quantity,
        'unit_price_amount' => $unitPrice,
        'total_amount' => $total,
    ]);

    Payment::factory()->create([
        'order_id' => $order->getKey(),
        'status' => PaymentStatus::Captured,
        'amount' => $total,
    ]);

    return [$order, $line, $variant];
}

test('refund service processes a partial line refund and restocks inventory', function () {
    [$order, $line, $variant] = refundServiceOrder();

    Event::fake();

    $refund = app(RefundService::class)->process($order, [
        'lines' => [$line->getKey() => 1],
        'reason' => 'Customer return',
        'restock' => true,
    ]);

    expect($refund->amount)->toBe(5000)
        ->and($refund->status)->toBe(RefundStatus::Processed)
        ->and($refund->provider_refund_id)->toStartWith('mock_refund_')
        ->and($order->refresh()->status)->toBe(OrderStatus::Paid)
        ->and($order->financial_status)->toBe(FinancialStatus::PartiallyRefunded)
        ->and($order->payments()->first()?->status)->toBe(PaymentStatus::Captured)
        ->and(InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->first()?->quantity_on_hand)->toBe(9);

    Event::assertDispatched(OrderRefunded::class, fn (OrderRefunded $event): bool => $event->refund->is($refund));
});

test('refund service marks order and payment refunded when the full amount is refunded', function () {
    [$order] = refundServiceOrder();

    $refund = app(RefundService::class)->process($order);

    expect($refund->amount)->toBe(10000)
        ->and($order->refresh()->status)->toBe(OrderStatus::Refunded)
        ->and($order->financial_status)->toBe(FinancialStatus::Refunded)
        ->and($order->payments()->first()?->status)->toBe(PaymentStatus::Refunded);
});

test('refund service rejects over-refunds and orders without captured payments', function () {
    [$order] = refundServiceOrder();

    expect(fn () => app(RefundService::class)->process($order, ['amount' => 10001]))
        ->toThrow(InvalidRefundOperationException::class);

    $order->payments()->update(['status' => PaymentStatus::Pending]);

    expect(fn () => app(RefundService::class)->process($order, ['amount' => 500]))
        ->toThrow(InvalidRefundOperationException::class);
});


sed -n '1,240p' app/Models/OrderLine.php


sed -n '1,220p' database/factories/OrderFactory.php


sed -n '1,220p' database/factories/PaymentFactory.php && sed -n '1,180p' database/factories/FulfillmentFactory.php


sed -n '1,240p' app/Models/OrderLine.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class OrderLine extends Model
{
    /** @use HasFactory<\Database\Factories\OrderLineFactory> */
    use HasFactory;

    public $timestamps = false;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'order_id',
        'product_id',
        'variant_id',
        'title_snapshot',
        'sku_snapshot',
        'quantity',
        'unit_price_amount',
        'total_amount',
        'tax_lines_json',
        'discount_allocations_json',
    ];

    /**
     * @return BelongsTo<Order, $this>
     */
    public function order(): BelongsTo
    {
        return $this->belongsTo(Order::class);
    }

    /**
     * @return BelongsTo<Product, $this>
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(Product::class);
    }

    /**
     * @return BelongsTo<ProductVariant, $this>
     */
    public function variant(): BelongsTo
    {
        return $this->belongsTo(ProductVariant::class, 'variant_id');
    }

    /**
     * @return HasMany<FulfillmentLine, $this>
     */
    public function fulfillmentLines(): HasMany
    {
        return $this->hasMany(FulfillmentLine::class);
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'quantity' => 'integer',
            'unit_price_amount' => 'integer',
            'total_amount' => 'integer',
            'tax_lines_json' => 'array',
            'discount_allocations_json' => 'array',
        ];
    }
}


/bin/zsh
-lc
sed -n '1,260p' app/Models/Order.php

<?php

namespace App\Models;

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Models\Concerns\BelongsToStore;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Order extends Model
{
    /** @use HasFactory<\Database\Factories\OrderFactory> */
    use BelongsToStore, HasFactory;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'store_id',
        'checkout_id',
        'customer_id',
        'order_number',
        'payment_method',
        'status',
        'financial_status',
        'fulfillment_status',
        'currency',
        'subtotal_amount',
        'discount_amount',
        'shipping_amount',
        'tax_amount',
        'total_amount',
        'email',
        'billing_address_json',
        'shipping_address_json',
        'placed_at',
    ];

    /**
     * @var array<string, mixed>
     */
    protected $attributes = [
        'status' => 'pending',
        'financial_status' => 'pending',
        'fulfillment_status' => 'unfulfilled',
        'currency' => 'USD',
        'subtotal_amount' => 0,
        'discount_amount' => 0,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => 0,
    ];

    /**
     * @return BelongsTo<Store, $this>
     */
    public function store(): BelongsTo
    {
        return $this->belongsTo(Store::class);
    }

    /**
     * @return BelongsTo<Checkout, $this>
     */
    public function checkout(): BelongsTo
    {
        return $this->belongsTo(Checkout::class);
    }

    /**
     * @return BelongsTo<Customer, $this>
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    /**
     * @return HasMany<OrderLine, $this>
     */
    public function lines(): HasMany
    {
        return $this->hasMany(OrderLine::class);
    }

    /**
     * @return HasMany<Payment, $this>
     */
    public function payments(): HasMany
    {
        return $this->hasMany(Payment::class);
    }

    /**
     * @return HasMany<Refund, $this>
     */
    public function refunds(): HasMany
    {
        return $this->hasMany(Refund::class);
    }

    /**
     * @return HasMany<Fulfillment, $this>
     */
    public function fulfillments(): HasMany
    {
        return $this->hasMany(Fulfillment::class);
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'payment_method' => PaymentMethod::class,
            'status' => OrderStatus::class,
            'financial_status' => FinancialStatus::class,
            'fulfillment_status' => FulfillmentStatus::class,
            'subtotal_amount' => 'integer',
            'discount_amount' => 'integer',
            'shipping_amount' => 'integer',
            'tax_amount' => 'integer',
            'total_amount' => 'integer',
            'billing_address_json' => 'array',
            'shipping_address_json' => 'array',
            'placed_at' => 'datetime',
        ];
    }
}


sed -n '1,220p' database/factories/OrderFactory.php

<?php

namespace Database\Factories;

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Models\Checkout;
use App\Models\Customer;
use App\Models\Store;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Order>
 */
class OrderFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $subtotal = fake()->numberBetween(2500, 25000);
        $shipping = fake()->randomElement([0, 499, 799]);
        $tax = 0;

        return [
            'store_id' => Store::factory(),
            'checkout_id' => null,
            'customer_id' => null,
            'order_number' => '#'.fake()->unique()->numberBetween(1001, 9999),
            'payment_method' => PaymentMethod::CreditCard,
            'status' => OrderStatus::Paid,
            'financial_status' => FinancialStatus::Paid,
            'fulfillment_status' => FulfillmentStatus::Unfulfilled,
            'currency' => 'EUR',
            'subtotal_amount' => $subtotal,
            'discount_amount' => 0,
            'shipping_amount' => $shipping,
            'tax_amount' => $tax,
            'total_amount' => $subtotal + $shipping + $tax,
            'email' => fake()->safeEmail(),
            'billing_address_json' => $this->address(),
            'shipping_address_json' => $this->address(),
            'placed_at' => now(),
        ];
    }

    public function forCheckout(?Checkout $checkout = null): static
    {
        return $this->state(fn (array $attributes): array => [
            'checkout_id' => $checkout?->getKey() ?? Checkout::factory(),
        ]);
    }

    public function forCustomer(?Customer $customer = null): static
    {
        return $this->state(fn (array $attributes): array => [
            'customer_id' => $customer?->getKey() ?? Customer::factory(),
        ]);
    }

    public function paid(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Paid,
            'financial_status' => FinancialStatus::Paid,
        ]);
    }

    public function pending(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Pending,
            'financial_status' => FinancialStatus::Pending,
        ]);
    }

    public function creditCard(): static
    {
        return $this->state(fn (array $attributes): array => [
            'payment_method' => PaymentMethod::CreditCard,
        ]);
    }

    public function paypal(): static
    {
        return $this->state(fn (array $attributes): array => [
            'payment_method' => PaymentMethod::Paypal,
        ]);
    }

    public function bankTransfer(): static
    {
        return $this->state(fn (array $attributes): array => [
            'payment_method' => PaymentMethod::BankTransfer,
            'status' => OrderStatus::Pending,
            'financial_status' => FinancialStatus::Pending,
        ]);
    }

    public function cancelled(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Cancelled,
            'financial_status' => FinancialStatus::Voided,
        ]);
    }

    public function partiallyFulfilled(): static
    {
        return $this->state(fn (array $attributes): array => [
            'fulfillment_status' => FulfillmentStatus::Partial,
        ]);
    }

    public function fulfilled(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Fulfilled,
            'financial_status' => FinancialStatus::Paid,
            'fulfillment_status' => FulfillmentStatus::Fulfilled,
        ]);
    }

    public function refunded(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Refunded,
            'financial_status' => FinancialStatus::Refunded,
        ]);
    }

    /**
     * @return array<string, string|null>
     */
    private function address(): array
    {
        return [
            'first_name' => fake()->firstName(),
            'last_name' => fake()->lastName(),
            'address1' => fake()->streetAddress(),
            'address2' => null,
            'city' => fake()->city(),
            'province_code' => null,
            'country' => 'DE',
            'postal_code' => fake()->postcode(),
        ];
    }
}


sed -n '1,220p' database/factories/PaymentFactory.php && sed -n '1,180p' database/factories/FulfillmentFactory.php

FulfillmentFactory.php

<?php

namespace Database\Factories;

use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Models\Order;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Payment>
 */
class PaymentFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'order_id' => Order::factory(),
            'provider' => 'mock',
            'method' => PaymentMethod::CreditCard,
            'provider_payment_id' => 'mock_payment_'.fake()->unique()->lexify('????????????????'),
            'status' => PaymentStatus::Captured,
            'amount' => fake()->numberBetween(2500, 25000),
            'currency' => 'EUR',
            'raw_json_encrypted' => [
                'success' => true,
                'status' => PaymentStatus::Captured->value,
            ],
        ];
    }

    public function pending(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => PaymentStatus::Pending,
        ]);
    }

    public function failed(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => PaymentStatus::Failed,
            'raw_json_encrypted' => [
                'success' => false,
                'status' => PaymentStatus::Failed->value,
                'error_code' => 'card_declined',
            ],
        ]);
    }

    public function refunded(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => PaymentStatus::Refunded,
        ]);
    }

    public function paypal(): static
    {
        return $this->state(fn (array $attributes): array => [
            'method' => PaymentMethod::Paypal,
        ]);
    }

    public function bankTransfer(): static
    {
        return $this->state(fn (array $attributes): array => [
            'method' => PaymentMethod::BankTransfer,
            'status' => PaymentStatus::Pending,
            'provider_payment_id' => 'mock_bank_'.fake()->unique()->lexify('????????????????'),
        ]);
    }
}
<?php

namespace Database\Factories;

use App\Enums\FulfillmentShipmentStatus;
use App\Models\Order;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Fulfillment>
 */
class FulfillmentFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'order_id' => Order::factory(),
            'status' => FulfillmentShipmentStatus::Pending,
            'tracking_company' => null,
            'tracking_number' => null,
            'tracking_url' => null,
            'shipped_at' => null,
            'delivered_at' => null,
        ];
    }

    public function withTracking(): static
    {
        return $this->state(fn (array $attributes): array => [
            'tracking_company' => fake()->randomElement(['DHL', 'UPS', 'DPD']),
            'tracking_number' => fake()->bothify('??##########'),
            'tracking_url' => fake()->url(),
        ]);
    }

    public function shipped(): static
    {
        return $this->withTracking()->state(fn (array $attributes): array => [
            'status' => FulfillmentShipmentStatus::Shipped,
            'shipped_at' => now(),
        ]);
    }

    public function delivered(): static
    {
        return $this->withTracking()->state(fn (array $attributes): array => [
            'status' => FulfillmentShipmentStatus::Delivered,
            'shipped_at' => now()->subDay(),
            'delivered_at' => now(),
        ]);
    }
}


Output:
Chunk ID: 5dfb25
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 808
Output:
<?php

namespace App\Models;

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Models\Concerns\BelongsToStore;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Order extends Model
{
    /** @use HasFactory<\Database\Factories\OrderFactory> */
    use BelongsToStore, HasFactory;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'store_id',
        'checkout_id',
        'customer_id',
        'order_number',
        'payment_method',
        'status',
        'financial_status',
        'fulfillment_status',
        'currency',
        'subtotal_amount',
        'discount_amount',
        'shipping_amount',
        'tax_amount',
        'total_amount',
        'email',
        'billing_address_json',
        'shipping_address_json',
        'placed_at',
    ];

    /**
     * @var array<string, mixed>
     */
    protected $attributes = [
        'status' => 'pending',
        'financial_status' => 'pending',
        'fulfillment_status' => 'unfulfilled',
        'currency' => 'USD',
        'subtotal_amount' => 0,
        'discount_amount' => 0,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => 0,
    ];

    /**
     * @return BelongsTo<Store, $this>
     */
    public function store(): BelongsTo
    {
        return $this->belongsTo(Store::class);
    }

    /**
     * @return BelongsTo<Checkout, $this>
     */
    public function checkout(): BelongsTo
    {
        return $this->belongsTo(Checkout::class);
    }

    /**
     * @return BelongsTo<Customer, $this>
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    /**
     * @return HasMany<OrderLine, $this>
     */
    public function lines(): HasMany
    {
        return $this->hasMany(OrderLine::class);
    }

    /**
     * @return HasMany<Payment, $this>
     */
    public function payments(): HasMany
    {
        return $this->hasMany(Payment::class);
    }

    /**
     * @return HasMany<Refund, $this>
     */
    public function refunds(): HasMany
    {
        return $this->hasMany(Refund::class);
    }

    /**
     * @return HasMany<Fulfillment, $this>
     */
    public function fulfillments(): HasMany
    {
        return $this->hasMany(Fulfillment::class);
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'payment_method' => PaymentMethod::class,
            'status' => OrderStatus::class,
            'financial_status' => FinancialStatus::class,
            'fulfillment_status' => FulfillmentStatus::class,
            'subtotal_amount' => 'integer',
            'discount_amount' => 'integer',
            'shipping_amount' => 'integer',
            'tax_amount' => 'integer',
            'total_amount' => 'integer',
            'billing_address_json' => 'array',
            'shipping_address_json' => 'array',
            'placed_at' => 'datetime',
        ];
    }
}


Output:
Chunk ID: 9049de
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 436
Output:
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class OrderLine extends Model
{
    /** @use HasFactory<\Database\Factories\OrderLineFactory> */
    use HasFactory;

    public $timestamps = false;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'order_id',
        'product_id',
        'variant_id',
        'title_snapshot',
        'sku_snapshot',
        'quantity',
        'unit_price_amount',
        'total_amount',
        'tax_lines_json',
        'discount_allocations_json',
    ];

    /**
     * @return BelongsTo<Order, $this>
     */
    public function order(): BelongsTo
    {
        return $this->belongsTo(Order::class);
    }

    /**
     * @return BelongsTo<Product, $this>
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(Product::class);
    }

    /**
     * @return BelongsTo<ProductVariant, $this>
     */
    public function variant(): BelongsTo
    {
        return $this->belongsTo(ProductVariant::class, 'variant_id');
    }

    /**
     * @return HasMany<FulfillmentLine, $this>
     */
    public function fulfillmentLines(): HasMany
    {
        return $this->hasMany(FulfillmentLine::class);
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'quantity' => 'integer',
            'unit_price_amount' => 'integer',
            'total_amount' => 'integer',
            'tax_lines_json' => 'array',
            'discount_allocations_json' => 'array',
        ];
    }
}


Output:
Chunk ID: 03ee78
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1152
Output:
<?php

namespace Database\Factories;

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Models\Checkout;
use App\Models\Customer;
use App\Models\Store;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Order>
 */
class OrderFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $subtotal = fake()->numberBetween(2500, 25000);
        $shipping = fake()->randomElement([0, 499, 799]);
        $tax = 0;

        return [
            'store_id' => Store::factory(),
            'checkout_id' => null,
            'customer_id' => null,
            'order_number' => '#'.fake()->unique()->numberBetween(1001, 9999),
            'payment_method' => PaymentMethod::CreditCard,
            'status' => OrderStatus::Paid,
            'financial_status' => FinancialStatus::Paid,
            'fulfillment_status' => FulfillmentStatus::Unfulfilled,
            'currency' => 'EUR',
            'subtotal_amount' => $subtotal,
            'discount_amount' => 0,
            'shipping_amount' => $shipping,
            'tax_amount' => $tax,
            'total_amount' => $subtotal + $shipping + $tax,
            'email' => fake()->safeEmail(),
            'billing_address_json' => $this->address(),
            'shipping_address_json' => $this->address(),
            'placed_at' => now(),
        ];
    }

    public function forCheckout(?Checkout $checkout = null): static
    {
        return $this->state(fn (array $attributes): array => [
            'checkout_id' => $checkout?->getKey() ?? Checkout::factory(),
        ]);
    }

    public function forCustomer(?Customer $customer = null): static
    {
        return $this->state(fn (array $attributes): array => [
            'customer_id' => $customer?->getKey() ?? Customer::factory(),
        ]);
    }

    public function paid(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Paid,
            'financial_status' => FinancialStatus::Paid,
        ]);
    }

    public function pending(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Pending,
            'financial_status' => FinancialStatus::Pending,
        ]);
    }

    public function creditCard(): static
    {
        return $this->state(fn (array $attributes): array => [
            'payment_method' => PaymentMethod::CreditCard,
        ]);
    }

    public function paypal(): static
    {
        return $this->state(fn (array $attributes): array => [
            'payment_method' => PaymentMethod::Paypal,
        ]);
    }

    public function bankTransfer(): static
    {
        return $this->state(fn (array $attributes): array => [
            'payment_method' => PaymentMethod::BankTransfer,
            'status' => OrderStatus::Pending,
            'financial_status' => FinancialStatus::Pending,
        ]);
    }

    public function cancelled(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Cancelled,
            'financial_status' => FinancialStatus::Voided,
        ]);
    }

    public function partiallyFulfilled(): static
    {
        return $this->state(fn (array $attributes): array => [
            'fulfillment_status' => FulfillmentStatus::Partial,
        ]);
    }

    public function fulfilled(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Fulfilled,
            'financial_status' => FinancialStatus::Paid,
            'fulfillment_status' => FulfillmentStatus::Fulfilled,
        ]);
    }

    public function refunded(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => OrderStatus::Refunded,
            'financial_status' => FinancialStatus::Refunded,
        ]);
    }

    /**
     * @return array<string, string|null>
     */
    private function address(): array
    {
        return [
            'first_name' => fake()->firstName(),
            'last_name' => fake()->lastName(),
            'address1' => fake()->streetAddress(),
            'address2' => null,
            'city' => fake()->city(),
            'province_code' => null,
            'country' => 'DE',
            'postal_code' => fake()->postcode(),
        ];
    }
}


Output:
Chunk ID: fccce5
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 957
Output:
<?php

namespace Database\Factories;

use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Models\Order;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Payment>
 */
class PaymentFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'order_id' => Order::factory(),
            'provider' => 'mock',
            'method' => PaymentMethod::CreditCard,
            'provider_payment_id' => 'mock_payment_'.fake()->unique()->lexify('????????????????'),
            'status' => PaymentStatus::Captured,
            'amount' => fake()->numberBetween(2500, 25000),
            'currency' => 'EUR',
            'raw_json_encrypted' => [
                'success' => true,
                'status' => PaymentStatus::Captured->value,
            ],
        ];
    }

    public function pending(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => PaymentStatus::Pending,
        ]);
    }

    public function failed(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => PaymentStatus::Failed,
            'raw_json_encrypted' => [
                'success' => false,
                'status' => PaymentStatus::Failed->value,
                'error_code' => 'card_declined',
            ],
        ]);
    }

    public function refunded(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => PaymentStatus::Refunded,
        ]);
    }

    public function paypal(): static
    {
        return $this->state(fn (array $attributes): array => [
            'method' => PaymentMethod::Paypal,
        ]);
    }

    public function bankTransfer(): static
    {
        return $this->state(fn (array $attributes): array => [
            'method' => PaymentMethod::BankTransfer,
            'status' => PaymentStatus::Pending,
            'provider_payment_id' => 'mock_bank_'.fake()->unique()->lexify('????????????????'),
        ]);
    }
}
<?php

namespace Database\Factories;

use App\Enums\FulfillmentShipmentStatus;
use App\Models\Order;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Fulfillment>
 */
class FulfillmentFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'order_id' => Order::factory(),
            'status' => FulfillmentShipmentStatus::Pending,
            'tracking_company' => null,
            'tracking_number' => null,
            'tracking_url' => null,
            'shipped_at' => null,
            'delivered_at' => null,
        ];
    }

    public function withTracking(): static
    {
        return $this->state(fn (array $attributes): array => [
            'tracking_company' => fake()->randomElement(['DHL', 'UPS', 'DPD']),
            'tracking_number' => fake()->bothify('??##########'),
            'tracking_url' => fake()->url(),
        ]);
    }

    public function shipped(): static
    {
        return $this->withTracking()->state(fn (array $attributes): array => [
            'status' => FulfillmentShipmentStatus::Shipped,
            'shipped_at' => now(),
        ]);
    }

    public function delivered(): static
    {
        return $this->withTracking()->state(fn (array $attributes): array => [
            'status' => FulfillmentShipmentStatus::Delivered,
            'shipped_at' => now()->subDay(),
            'delivered_at' => now(),
        ]);
    }
}


php artisan make:livewire Admin/Orders/Index --class --no-interaction && php artisan make:livewire Admin/Orders/Show --class --no-interaction && php artisan make:test --pest Admin/OrderManagementTest --no-interaction


Output:
Chunk ID: dc78a4
Wall time: 0.5113 seconds
Process exited with code 0
Original token count: 68
Output:

   INFO  Livewire component [app/Livewire/Admin/Orders/Index.php] created successfully.

   INFO  Livewire component [app/Livewire/Admin/Orders/Show.php] created successfully.

   INFO  Test [tests/Feature/Admin/OrderManagementTest.php] created successfully.


php artisan make:livewire Admin/Orders/Index --class --no-interaction && php artisan make:livewire Admin/Orders/Show --class --no-interaction && php artisan make:test --pest Admin/OrderManagementTest --no-interaction

   INFO  Livewire component [app/Livewire/Admin/Orders/Index.php] created successfully.

   INFO  Livewire component [app/Livewire/Admin/Orders/Show.php] created successfully.

   INFO  Test [tests/Feature/Admin/OrderManagementTest.php] created successfully.


sed -n '1,160p' app/Livewire/Admin/Orders/Index.php


sed -n '1,160p' app/Livewire/Admin/Orders/Show.php


sed -n '1,180p' resources/views/livewire/admin/orders/index.blade.php


sed -n '1,180p' resources/views/livewire/admin/orders/show.blade.php


sed -n '1,160p' app/Livewire/Admin/Orders/Index.php

<?php

namespace App\Livewire\Admin\Orders;

use Livewire\Component;

class Index extends Component
{
    public function render()
    {
        return view('livewire.admin.orders.index');
    }
}


sed -n '1,160p' app/Livewire/Admin/Orders/Show.php

<?php

namespace App\Livewire\Admin\Orders;

use Livewire\Component;

class Show extends Component
{
    public function render()
    {
        return view('livewire.admin.orders.show');
    }
}


sed -n '1,180p' resources/views/livewire/admin/orders/show.blade.php

{{-- Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant --}}


sed -n '1,180p' resources/views/livewire/admin/orders/index.blade.php

{{-- He who is contented is rich. - Laozi --}}


Output:
Chunk ID: 9e0997
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 50
Output:
<?php

namespace App\Livewire\Admin\Orders;

use Livewire\Component;

class Index extends Component
{
    public function render()
    {
        return view('livewire.admin.orders.index');
    }
}


Output:
Chunk ID: 1a7219
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 49
Output:
<?php

namespace App\Livewire\Admin\Orders;

use Livewire\Component;

class Show extends Component
{
    public function render()
    {
        return view('livewire.admin.orders.show');
    }
}


Output:
Chunk ID: 8ce2a6
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 16
Output:
<div>
    {{-- He who is contented is rich. - Laozi --}}
</div>


Output:
Chunk ID: 1b0def
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 39
Output:
<div>
    {{-- Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant --}}
</div>


rg -n "current_store|StoreScope|store_id|admin" app bootstrap routes database -g '*.php'


sed -n '1,220p' app/Http/Middleware/ResolveStore.php


sed -n '1,220p' app/Http/Middleware/EnsureAdminUser.php


sed -n '1,220p' app/Models/Concerns/BelongsToStore.php && sed -n '1,160p' app/Models/Scopes/StoreScope.php


sed -n '1,220p' app/Http/Middleware/ResolveStore.php

<?php

namespace App\Http\Middleware;

use App\Enums\StoreStatus;
use App\Models\Store;
use App\Models\StoreDomain;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpFoundation\Response;

class ResolveStore
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        $store = $request->is('admin*')
            ? $this->resolveAdminStore($request)
            : $this->resolveStorefrontStore($request);

        abort_unless($store, 404);

        app()->instance('current_store', $store);

        if (! $request->is('admin*') && $store->status === StoreStatus::Suspended) {
            abort(503);
        }

        if ($request->is('admin*') && $store->status === StoreStatus::Suspended && ! $request->isMethodSafe()) {
            abort(403);
        }

        return $next($request);
    }

    private function resolveStorefrontStore(Request $request): ?Store
    {
        $hostname = $request->getHost();
        $cacheKey = "store_domain:{$hostname}";

        $storeId = Cache::remember($cacheKey, now()->addMinutes(5), function () use ($hostname): ?int {
            return StoreDomain::query()
                ->where('hostname', $hostname)
                ->value('store_id');
        });

        return $storeId ? Store::query()->find($storeId) : null;
    }

    private function resolveAdminStore(Request $request): ?Store
    {
        $user = $request->user();

        if (! $user) {
            return null;
        }

        $storeId = $request->session()->get('current_store_id');

        if (! $storeId) {
            $storeId = $user->stores()->oldest('stores.id')->value('stores.id');

            if ($storeId) {
                $request->session()->put('current_store_id', $storeId);
            }
        }

        if (! $storeId || ! $user->stores()->whereKey($storeId)->exists()) {
            return null;
        }

        return Store::query()->find($storeId);
    }
}


sed -n '1,220p' app/Http/Middleware/EnsureAdminUser.php

sed: app/Http/Middleware/EnsureAdminUser.php: No such file or directory


sed -n '1,220p' app/Models/Concerns/BelongsToStore.php && sed -n '1,160p' app/Models/Scopes/StoreScope.php

StoreScope.php

<?php

namespace App\Models\Concerns;

use App\Models\Scopes\StoreScope;
use App\Models\Store;

trait BelongsToStore
{
    public static function bootBelongsToStore(): void
    {
        static::addGlobalScope(new StoreScope);

        static::creating(function (object $model): void {
            if ($model->store_id || ! app()->bound('current_store')) {
                return;
            }

            $store = app('current_store');

            if ($store instanceof Store) {
                $model->store_id = $store->getKey();
            }
        });
    }
}
<?php

namespace App\Models\Scopes;

use App\Models\Store;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class StoreScope implements Scope
{
    public function apply(Builder $builder, Model $model): void
    {
        if (! app()->bound('current_store')) {
            return;
        }

        $store = app('current_store');

        if (! $store instanceof Store) {
            return;
        }

        $builder->where($model->qualifyColumn('store_id'), $store->getKey());
    }
}


rg -n "current_store|StoreScope|store_id|admin" app bootstrap routes database -g '*.php'

rg -n 'current_store|StoreScope|store_id|admin' app bootstrap routes database -g '*.php'

database/factories/ShippingZoneFactory.php:21:            'store_id' => Store::factory(),
routes/web.php:37:Route::livewire('admin/login', AdminLogin::class)
routes/web.php:39:    ->name('admin.login');
routes/web.php:41:Route::post('admin/logout', function () {
routes/web.php:47:    return redirect()->route('admin.login');
routes/web.php:48:})->middleware('auth')->name('admin.logout');
routes/web.php:50:Route::middleware(['auth', 'verified', 'admin'])->prefix('admin')->name('admin.')->group(function (): void {
routes/web.php:79:Route::redirect('dashboard', 'admin')
database/factories/ProductFactory.php:27:            'store_id' => Store::factory(),
bootstrap/app.php:26:        $middleware->appendToGroup('admin', [
database/factories/NavigationMenuFactory.php:24:            'store_id' => Store::factory(),
database/factories/StoreSettingsFactory.php:21:            'store_id' => Store::factory(),
database/factories/DiscountFactory.php:24:            'store_id' => Store::factory(),
database/factories/TaxSettingsFactory.php:22:            'store_id' => Store::factory(),
database/factories/InventoryItemFactory.php:26:            'store_id' => fn (array $attributes): mixed => ProductVariant::query()
database/factories/InventoryItemFactory.php:30:                ?->store_id ?? Store::factory(),
app/Support/HandleGenerator.php:29:            ->where('store_id', $storeId)
database/factories/PageFactory.php:25:            'store_id' => Store::factory(),
database/factories/CustomerFactory.php:21:            'store_id' => Store::factory(),
database/factories/CartFactory.php:23:            'store_id' => Store::factory(),
database/factories/OrderFactory.php:31:            'store_id' => Store::factory(),
database/factories/CheckoutFactory.php:24:            'store_id' => Store::factory(),
app/Models/Order.php:24:        'store_id',
database/factories/CollectionFactory.php:26:            'store_id' => Store::factory(),
database/factories/ThemeFactory.php:22:            'store_id' => Store::factory(),
app/Models/Concerns/BelongsToStore.php:5:use App\Models\Scopes\StoreScope;
app/Models/Concerns/BelongsToStore.php:12:        static::addGlobalScope(new StoreScope);
app/Models/Concerns/BelongsToStore.php:15:            if ($model->store_id || ! app()->bound('current_store')) {
app/Models/Concerns/BelongsToStore.php:19:            $store = app('current_store');
app/Models/Concerns/BelongsToStore.php:22:                $model->store_id = $store->getKey();
app/Auth/CustomerUserProvider.php:36:        $store = app()->bound('current_store') ? app('current_store') : null;
app/Auth/CustomerUserProvider.php:42:        $query->where('store_id', $store->getKey());
database/factories/StoreDomainFactory.php:22:            'store_id' => Store::factory(),
database/factories/StoreDomainFactory.php:30:    public function admin(): static
app/Models/NavigationItem.php:40:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/NavigationItem.php:41:            if (! app()->bound('current_store')) {
app/Models/NavigationItem.php:45:            $store = app('current_store');
app/Models/NavigationItem.php:54:                    ->where('store_id', $store->getKey());
app/Models/NavigationMenu.php:20:        'store_id',
app/Models/ProductOption.php:36:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductOption.php:37:            if (! app()->bound('current_store')) {
app/Models/ProductOption.php:41:            $store = app('current_store');
app/Models/ProductOption.php:50:                    ->where('store_id', $store->getKey());
app/Services/VariantMatrixService.php:89:                    'store_id' => $product->store_id,
app/Services/VariantMatrixService.php:111:                'store_id' => $product->store_id,
app/Services/VariantMatrixService.php:183:                'store_id' => $product->store_id,
app/Services/VariantMatrixService.php:201:        return Store::query()->findOrFail($product->store_id);
app/Models/Scopes/StoreScope.php:10:class StoreScope implements Scope
app/Models/Scopes/StoreScope.php:14:        if (! app()->bound('current_store')) {
app/Models/Scopes/StoreScope.php:18:        $store = app('current_store');
app/Models/Scopes/StoreScope.php:24:        $builder->where($model->qualifyColumn('store_id'), $store->getKey());
app/Traits/ChecksStoreRole.php:54:        if (! app()->bound('current_store')) {
app/Traits/ChecksStoreRole.php:58:        $store = app('current_store');
app/Traits/ChecksStoreRole.php:66:            $storeId = $model->getAttribute('store_id');
app/Traits/ChecksStoreRole.php:71:        if (property_exists($model, 'store_id')) {
app/Traits/ChecksStoreRole.php:72:            return is_numeric($model->store_id) ? (int) $model->store_id : null;
app/Models/InventoryItem.php:23:        'store_id',
app/Models/InventoryItem.php:48:            if (! $item->store_id) {
app/Models/InventoryItem.php:49:                $item->store_id = $s…16703 chars truncated…create_pages_table.php:25:            $table->index('store_id');
database/migrations/2026_05_03_223841_create_pages_table.php:26:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_223824_create_themes_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_223824_create_themes_table.php:23:            $table->index('store_id');
database/migrations/2026_05_03_223824_create_themes_table.php:24:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_211425_create_store_users_table.php:15:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_211425_create_store_users_table.php:17:            $table->enum('role', ['owner', 'admin', 'staff', 'support'])->default('staff');
database/migrations/2026_05_03_211425_create_store_users_table.php:20:            $table->primary(['store_id', 'user_id']);
database/migrations/2026_05_03_211425_create_store_users_table.php:22:            $table->index(['store_id', 'role']);
database/migrations/2026_05_03_211416_create_store_domains_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_211416_create_store_domains_table.php:18:            $table->enum('type', ['storefront', 'admin', 'api'])->default('storefront');
database/migrations/2026_05_03_211416_create_store_domains_table.php:23:            $table->index('store_id');
database/migrations/2026_05_03_211416_create_store_domains_table.php:24:            $table->index(['store_id', 'is_primary']);
database/migrations/2026_05_03_225413_create_shipping_zones_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_225413_create_shipping_zones_table.php:21:            $table->index('store_id');
database/migrations/2026_05_03_225422_create_tax_settings_table.php:15:            $table->foreignId('store_id')->primary()->constrained()->cascadeOnDelete();
app/Providers/AppServiceProvider.php:82:            if ($request->is('admin*')) {
app/Providers/AppServiceProvider.php:83:                return route('admin.login');
app/Providers/AppServiceProvider.php:97:            $store = app()->bound('current_store') ? app('current_store') : null;
database/migrations/2026_05_03_225427_create_discounts_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_225427_create_discounts_table.php:29:            $table->unique(['store_id', 'code']);
database/migrations/2026_05_03_225427_create_discounts_table.php:30:            $table->index('store_id');
database/migrations/2026_05_03_225427_create_discounts_table.php:31:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_225427_create_discounts_table.php:32:            $table->index(['store_id', 'type']);
database/migrations/2026_05_03_211556_create_customers_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_211556_create_customers_table.php:23:            $table->unique(['store_id', 'email']);
database/migrations/2026_05_03_211556_create_customers_table.php:24:            $table->index('store_id');
database/migrations/2026_05_03_223844_create_navigation_menus_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_223844_create_navigation_menus_table.php:21:            $table->unique(['store_id', 'handle']);
database/migrations/2026_05_03_223844_create_navigation_menus_table.php:22:            $table->index('store_id');
database/migrations/2026_05_03_213856_create_products_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213856_create_products_table.php:27:            $table->unique(['store_id', 'handle']);
database/migrations/2026_05_03_213856_create_products_table.php:28:            $table->index('store_id');
database/migrations/2026_05_03_213856_create_products_table.php:29:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_213856_create_products_table.php:30:            $table->index(['store_id', 'published_at']);
database/migrations/2026_05_03_213856_create_products_table.php:31:            $table->index(['store_id', 'vendor']);
database/migrations/2026_05_03_213856_create_products_table.php:32:            $table->index(['store_id', 'product_type']);
database/migrations/2026_05_03_211419_create_store_settings_table.php:15:            $table->foreignId('store_id')->primary()->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213901_create_inventory_items_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213901_create_inventory_items_table.php:22:            $table->index('store_id');


Output:
Chunk ID: 41f4d8
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 6676
Output:
database/factories/ShippingZoneFactory.php:21:            'store_id' => Store::factory(),
routes/web.php:37:Route::livewire('admin/login', AdminLogin::class)
routes/web.php:39:    ->name('admin.login');
routes/web.php:41:Route::post('admin/logout', function () {
routes/web.php:47:    return redirect()->route('admin.login');
routes/web.php:48:})->middleware('auth')->name('admin.logout');
routes/web.php:50:Route::middleware(['auth', 'verified', 'admin'])->prefix('admin')->name('admin.')->group(function (): void {
routes/web.php:79:Route::redirect('dashboard', 'admin')
database/factories/ProductFactory.php:27:            'store_id' => Store::factory(),
bootstrap/app.php:26:        $middleware->appendToGroup('admin', [
database/factories/NavigationMenuFactory.php:24:            'store_id' => Store::factory(),
database/factories/StoreSettingsFactory.php:21:            'store_id' => Store::factory(),
database/factories/DiscountFactory.php:24:            'store_id' => Store::factory(),
database/factories/TaxSettingsFactory.php:22:            'store_id' => Store::factory(),
database/factories/InventoryItemFactory.php:26:            'store_id' => fn (array $attributes): mixed => ProductVariant::query()
database/factories/InventoryItemFactory.php:30:                ?->store_id ?? Store::factory(),
app/Support/HandleGenerator.php:29:            ->where('store_id', $storeId)
database/factories/PageFactory.php:25:            'store_id' => Store::factory(),
database/factories/CustomerFactory.php:21:            'store_id' => Store::factory(),
database/factories/CartFactory.php:23:            'store_id' => Store::factory(),
database/factories/OrderFactory.php:31:            'store_id' => Store::factory(),
database/factories/CheckoutFactory.php:24:            'store_id' => Store::factory(),
app/Models/Order.php:24:        'store_id',
database/factories/CollectionFactory.php:26:            'store_id' => Store::factory(),
database/factories/ThemeFactory.php:22:            'store_id' => Store::factory(),
app/Models/Concerns/BelongsToStore.php:5:use App\Models\Scopes\StoreScope;
app/Models/Concerns/BelongsToStore.php:12:        static::addGlobalScope(new StoreScope);
app/Models/Concerns/BelongsToStore.php:15:            if ($model->store_id || ! app()->bound('current_store')) {
app/Models/Concerns/BelongsToStore.php:19:            $store = app('current_store');
app/Models/Concerns/BelongsToStore.php:22:                $model->store_id = $store->getKey();
app/Auth/CustomerUserProvider.php:36:        $store = app()->bound('current_store') ? app('current_store') : null;
app/Auth/CustomerUserProvider.php:42:        $query->where('store_id', $store->getKey());
database/factories/StoreDomainFactory.php:22:            'store_id' => Store::factory(),
database/factories/StoreDomainFactory.php:30:    public function admin(): static
app/Models/NavigationItem.php:40:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/NavigationItem.php:41:            if (! app()->bound('current_store')) {
app/Models/NavigationItem.php:45:            $store = app('current_store');
app/Models/NavigationItem.php:54:                    ->where('store_id', $store->getKey());
app/Models/NavigationMenu.php:20:        'store_id',
app/Models/ProductOption.php:36:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductOption.php:37:            if (! app()->bound('current_store')) {
app/Models/ProductOption.php:41:            $store = app('current_store');
app/Models/ProductOption.php:50:                    ->where('store_id', $store->getKey());
app/Services/VariantMatrixService.php:89:                    'store_id' => $product->store_id,
app/Services/VariantMatrixService.php:111:                'store_id' => $product->store_id,
app/Services/VariantMatrixService.php:183:                'store_id' => $product->store_id,
app/Services/VariantMatrixService.php:201:        return Store::query()->findOrFail($product->store_id);
app/Models/Scopes/StoreScope.php:10:class StoreScope implements Scope
app/Models/Scopes/StoreScope.php:14:        if (! app()->bound('current_store')) {
app/Models/Scopes/StoreScope.php:18:        $store = app('current_store');
app/Models/Scopes/StoreScope.php:24:        $builder->where($model->qualifyColumn('store_id'), $store->getKey());
app/Traits/ChecksStoreRole.php:54:        if (! app()->bound('current_store')) {
app/Traits/ChecksStoreRole.php:58:        $store = app('current_store');
app/Traits/ChecksStoreRole.php:66:            $storeId = $model->getAttribute('store_id');
app/Traits/ChecksStoreRole.php:71:        if (property_exists($model, 'store_id')) {
app/Traits/ChecksStoreRole.php:72:            return is_numeric($model->store_id) ? (int) $model->store_id : null;
app/Models/InventoryItem.php:23:        'store_id',
app/Models/InventoryItem.php:48:            if (! $item->store_id) {
app/Models/InventoryItem.php:49:                $item->store_id = $storeId;
app/Models/InventoryItem.php:54:            if ((int) $item->store_id !== $storeId) {
app/Models/InventoryItem.php:72:            ->value('store_id');
app/Models/ThemeFile.php:37:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ThemeFile.php:38:            if (! app()->bound('current_store')) {
app/Models/ThemeFile.php:42:            $store = app('current_store');
app/Models/ThemeFile.php:51:                    ->where('store_id', $store->getKey());
app/Services/DiscountService.php:25:            ->where('store_id', $store->getKey())
app/Models/StoreUser.php:22:        'store_id',
app/Models/Cart.php:21:        'store_id',
app/Services/PricingEngine.php:125:            ->where('store_id', $checkout->store_id)
app/Services/PricingEngine.php:127:                'store_id' => $checkout->store_id,
app/Models/CartLine.php:43:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/CartLine.php:44:            if (! app()->bound('current_store')) {
app/Models/CartLine.php:48:            $store = app('current_store');
app/Models/CartLine.php:57:                    ->where('store_id', $store->getKey());
database/seeders/DiscountSeeder.php:20:                        'store_id' => $store->getKey(),
app/Models/StoreSettings.php:18:    protected $primaryKey = 'store_id';
app/Models/StoreSettings.php:24:        'store_id',
app/Models/Product.php:22:        'store_id',
app/Models/Discount.php:22:        'store_id',
app/Models/ShippingRate.php:40:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ShippingRate.php:41:            if (! app()->bound('current_store')) {
app/Models/ShippingRate.php:45:            $store = app('current_store');
app/Models/ShippingRate.php:54:                    ->where('store_id', $store->getKey());
app/Jobs/ProcessMediaUpload.php:66:                    ->where('store_id', $this->storeId);
app/Models/Checkout.php:20:        'store_id',
app/Models/ProductMedia.php:47:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductMedia.php:48:            if (! app()->bound('current_store')) {
app/Models/ProductMedia.php:52:            $store = app('current_store');
app/Models/ProductMedia.php:61:                    ->where('store_id', $store->getKey());
app/Models/Page.php:20:        'store_id',
app/Services/CartService.php:27:            'store_id' => $store->getKey(),
app/Services/CartService.php:41:                ->where('store_id', $store->getKey())
app/Services/CartService.php:49:                    ->where('store_id', $store->getKey())
app/Services/CartService.php:66:                ->where('store_id', $store->getKey())
app/Services/CartService.php:86:                ->where('store_id', $store->getKey())
app/Services/CartService.php:104:            ->where('store_id', $store->getKey())
app/Services/CartService.php:248:        if ((int) $variant->product->store_id !== (int) $cart->store_id) {
app/Models/Theme.php:22:        'store_id',
app/Services/ThemeSettingsService.php:34:            ->where('store_id', $store->getKey())
app/Models/ThemeSettings.php:31:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ThemeSettings.php:32:            if (! app()->bound('current_store')) {
app/Models/ThemeSettings.php:36:            $store = app('current_store');
app/Models/ThemeSettings.php:45:                    ->where('store_id', $store->getKey());
app/Services/ShippingCalculator.php:46:            ->where('store_id', $store->getKey())
app/Models/StoreDomain.php:21:        'store_id',
app/Livewire/Storefront/Account/Orders/Show.php:22:        $store = app('current_store');
app/Livewire/Storefront/Account/Orders/Show.php:28:            ->where('store_id', $store->getKey())
app/Livewire/Storefront/Account/Orders/Show.php:52:            ->where('store_id', $this->storeId)
app/Livewire/Admin/Collections/Form.php:36:            $store = app('current_store');
app/Livewire/Admin/Collections/Form.php:38:            abort_unless($store instanceof Store && (int) $collection->store_id === $store->getKey(), 404);
app/Livewire/Admin/Collections/Form.php:71:        $store = app('current_store');
app/Livewire/Admin/Collections/Form.php:81:                    ->where('store_id', $store->getKey())
app/Livewire/Admin/Collections/Form.php:89:            'store_id' => $store->getKey(),
app/Livewire/Admin/Collections/Form.php:145:        return view('livewire.admin.collections.form', [
app/Services/ProductService.php:43:                'store_id' => $store->getKey(),
app/Services/ProductService.php:87:            $storeId = $product->store_id;
app/Services/ProductService.php:181:                'store_id' => $store->getKey(),
app/Services/ProductService.php:289:            ->whereHas('product', fn ($query) => $query->where('store_id', $store->getKey()));
app/Services/CheckoutService.php:41:            'store_id' => $cart->store_id,
database/seeders/PageSeeder.php:20:                        'store_id' => $store->getKey(),
app/Models/ProductVariant.php:51:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductVariant.php:52:            if (! app()->bound('current_store')) {
app/Models/ProductVariant.php:56:            $store = app('current_store');
app/Models/ProductVariant.php:65:                    ->where('store_id', $store->getKey());
app/Models/ProductVariant.php:80:                ->value('store_id');
app/Models/ProductVariant.php:87:                'store_id' => $storeId,
app/Models/ProductVariant.php:106:            ->value('store_id');
app/Models/ProductVariant.php:117:                    ->where('store_id', $storeId);
app/Models/Customer.php:21:        'store_id',
app/Livewire/Admin/Collections/Index.php:50:        return view('livewire.admin.collections.index', [
app/Livewire/Storefront/Account/Orders/Index.php:20:        $store = app('current_store');
app/Livewire/Storefront/Account/Orders/Index.php:46:            ->where('store_id', $this->storeId)
app/Services/NavigationService.php:23:            ->where('store_id', $store->getKey())
app/Services/NavigationService.php:72:            ->where('store_id', $this->storeIdFor($item))
app/Services/NavigationService.php:81:            ->where('store_id', $this->storeIdFor($item))
app/Services/NavigationService.php:90:            ->where('store_id', $this->storeIdFor($item))
app/Services/NavigationService.php:99:            return (int) $item->menu->store_id;
app/Services/NavigationService.php:104:            ->value('store_id');
app/Services/NavigationService.php:114:        return "navigation:{$menu->store_id}:{$menu->handle}";
app/Models/ProductOptionValue.php:36:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductOptionValue.php:37:            if (! app()->bound('current_store')) {
app/Models/ProductOptionValue.php:41:            $store = app('current_store');
app/Models/ProductOptionValue.php:50:                    ->where('store_id', $store->getKey());
app/Models/Collection.php:22:        'store_id',
app/Livewire/Admin/Orders/Show.php:11:        return view('livewire.admin.orders.show');
app/Models/ShippingZone.php:22:        'store_id',
app/Services/OrderService.php:79:                    'store_id' => $checkout->store_id,
app/Services/OrderService.php:229:            ->where('store_id', $store->getKey())
app/Services/OrderService.php:235:            ->where('store_id', $store->getKey())
app/Services/OrderService.php:352:            ->where('store_id', $checkout->store_id)
app/Enums/StoreDomainType.php:8:    case Admin = 'admin';
app/Livewire/Storefront/Account/Auth/Register.php:27:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Register.php:38:        app()->instance('current_store', $store);
app/Livewire/Storefront/Account/Auth/Register.php:46:                Rule::unique('customers', 'email')->where('store_id', $store->getKey()),
app/Livewire/Storefront/Account/Auth/Register.php:53:            'store_id' => $store->getKey(),
app/Livewire/Admin/Orders/Index.php:11:        return view('livewire.admin.orders.index');
app/Models/TaxSettings.php:20:    protected $primaryKey = 'store_id';
app/Models/TaxSettings.php:26:        'store_id',
app/Livewire/Storefront/Checkout/Confirmation.php:22:        $store = app('current_store');
app/Livewire/Storefront/Checkout/Confirmation.php:27:            ->where('store_id', $store->getKey())
app/Livewire/Storefront/Checkout/Confirmation.php:62:            ->where('store_id', $this->storeId)
app/Livewire/Storefront/Account/Auth/Login.php:25:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Login.php:50:        app()->instance('current_store', Store::query()->findOrFail($this->storeId));
database/seeders/CollectionSeeder.php:35:                        'store_id' => $store->getKey(),
app/Livewire/Storefront/Home.php:16:        $store = app('current_store');
app/Livewire/Admin/Inventory/Index.php:50:        return view('livewire.admin.inventory.index', [
app/Livewire/Storefront/Checkout/Show.php:257:            app()->instance('current_store', $store);
app/Livewire/Storefront/Checkout/Show.php:262:        $store = app('current_store');
app/Livewire/Storefront/Products/Show.php:92:            app()->instance('current_store', $store);
app/Livewire/Storefront/Products/Show.php:97:        $store = app('current_store');
database/seeders/StoreUserSeeder.php:17:        $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
database/seeders/StoreUserSeeder.php:22:                    'store_id' => $store->getKey(),
app/Http/Controllers/Api/Storefront/V1/CartController.php:31:        $store = app('current_store');
app/Livewire/Storefront/Cart/Show.php:144:            app()->instance('current_store', $store);
app/Livewire/Storefront/Cart/Show.php:149:        $store = app('current_store');
app/Livewire/Storefront/CartDrawer.php:76:            app()->instance('current_store', $store);
app/Livewire/Storefront/CartDrawer.php:81:        $store = app('current_store');
app/Livewire/Admin/Auth/Login.php:26:        $key = 'admin-login:'.request()->ip();
app/Livewire/Admin/Auth/Login.php:56:        $this->redirectRoute('admin.dashboard', navigate: true);
app/Livewire/Admin/Auth/Login.php:61:        return view('livewire.admin.auth.login')
app/Livewire/Admin/Products/Form.php:58:            $store = app('current_store');
app/Livewire/Admin/Products/Form.php:60:            abort_unless($store instanceof Store && (int) $product->store_id === $store->getKey(), 404);
app/Livewire/Admin/Products/Form.php:102:        $store = app('current_store');
app/Livewire/Admin/Products/Form.php:117:                    ->where('store_id', $store->getKey())
app/Livewire/Admin/Products/Form.php:173:        $this->redirectRoute('admin.products.index', navigate: true);
app/Livewire/Admin/Products/Form.php:178:        return view('livewire.admin.products.form', [
app/Livewire/Admin/Products/Form.php:305:                    'store_id' => $store->getKey(),
app/Livewire/Admin/Products/Form.php:362:                    ->where('store_id', $store->getKey());
database/seeders/ThemeSeeder.php:19:                    'store_id' => $store->getKey(),
app/Livewire/Admin/Products/Index.php:123:        return view('livewire.admin.products.index', [
database/seeders/TaxSettingsSeeder.php:18:                ['store_id' => $store->getKey()],
database/seeders/UserSeeder.php:16:            ['email' => 'admin@acme.test'],
database/seeders/StoreDomainSeeder.php:28:                        'store_id' => $store->getKey(),
database/seeders/ShippingZoneSeeder.php:19:                    'store_id' => $store->getKey(),
app/Http/Resources/Storefront/V1/CartResource.php:21:            'store_id' => $this->store_id,
database/seeders/NavigationMenuSeeder.php:23:                        'store_id' => $store->getKey(),
database/seeders/ProductSeeder.php:35:            ->where('store_id', $store->getKey())
database/seeders/ProductSeeder.php:42:                    'store_id' => $store->getKey(),
database/seeders/ProductSeeder.php:47:                    'store_id' => $store->getKey(),
database/seeders/ProductSeeder.php:141:                    'store_id' => $store->getKey(),
app/Http/Resources/Storefront/V1/CheckoutResource.php:19:            'store_id' => $this->store_id,
database/seeders/StoreSettingsSeeder.php:18:                ['store_id' => $store->getKey()],
app/Http/Middleware/ResolveStore.php:22:        $store = $request->is('admin*')
app/Http/Middleware/ResolveStore.php:28:        app()->instance('current_store', $store);
app/Http/Middleware/ResolveStore.php:30:        if (! $request->is('admin*') && $store->status === StoreStatus::Suspended) {
app/Http/Middleware/ResolveStore.php:34:        if ($request->is('admin*') && $store->status === StoreStatus::Suspended && ! $request->isMethodSafe()) {
app/Http/Middleware/ResolveStore.php:49:                ->value('store_id');
app/Http/Middleware/ResolveStore.php:63:        $storeId = $request->session()->get('current_store_id');
app/Http/Middleware/ResolveStore.php:69:                $request->session()->put('current_store_id', $storeId);
database/seeders/CustomerSeeder.php:20:                'store_id' => $store->getKey(),
app/Http/Middleware/CheckStoreRole.php:20:        $store = app()->bound('current_store') ? app('current_store') : null;
database/migrations/2026_05_03_213902_create_collections_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213902_create_collections_table.php:24:            $table->unique(['store_id', 'handle']);
database/migrations/2026_05_03_213902_create_collections_table.php:25:            $table->index('store_id');
database/migrations/2026_05_03_213902_create_collections_table.php:26:            $table->index(['store_id', 'status']);
database/seeders/NavigationItemSeeder.php:21:                ->where('store_id', $store->getKey())
database/seeders/NavigationItemSeeder.php:93:            ->where('store_id', $store->getKey())
database/seeders/NavigationItemSeeder.php:101:            ->where('store_id', $store->getKey())
database/migrations/2026_05_03_212158_create_customer_password_reset_tokens_table.php:15:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_212158_create_customer_password_reset_tokens_table.php:20:            $table->primary(['store_id', 'email']);
database/migrations/2026_05_04_000408_create_orders_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_04_000408_create_orders_table.php:36:            $table->unique(['store_id', 'order_number']);
database/migrations/2026_05_04_000408_create_orders_table.php:38:            $table->index('store_id');
database/migrations/2026_05_04_000408_create_orders_table.php:40:            $table->index(['store_id', 'status']);
database/migrations/2026_05_04_000408_create_orders_table.php:41:            $table->index(['store_id', 'financial_status']);
database/migrations/2026_05_04_000408_create_orders_table.php:42:            $table->index(['store_id', 'fulfillment_status']);
database/migrations/2026_05_04_000408_create_orders_table.php:43:            $table->index(['store_id', 'placed_at']);
app/Http/Requests/Api/Storefront/V1/StoreCartRequest.php:27:        $store = app()->bound('current_store') ? app('current_store') : null;
database/migrations/2026_05_03_225409_create_checkouts_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_225409_create_checkouts_table.php:31:            $table->index('store_id');
database/migrations/2026_05_03_225409_create_checkouts_table.php:34:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_225400_create_carts_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_225400_create_carts_table.php:23:            $table->index('store_id');
database/migrations/2026_05_03_225400_create_carts_table.php:25:            $table->index(['store_id', 'status']);
app/Enums/StoreUserRole.php:8:    case Admin = 'admin';
database/migrations/2026_05_03_223841_create_pages_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_223841_create_pages_table.php:24:            $table->unique(['store_id', 'handle']);
database/migrations/2026_05_03_223841_create_pages_table.php:25:            $table->index('store_id');
database/migrations/2026_05_03_223841_create_pages_table.php:26:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_223824_create_themes_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_223824_create_themes_table.php:23:            $table->index('store_id');
database/migrations/2026_05_03_223824_create_themes_table.php:24:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_211425_create_store_users_table.php:15:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_211425_create_store_users_table.php:17:            $table->enum('role', ['owner', 'admin', 'staff', 'support'])->default('staff');
database/migrations/2026_05_03_211425_create_store_users_table.php:20:            $table->primary(['store_id', 'user_id']);
database/migrations/2026_05_03_211425_create_store_users_table.php:22:            $table->index(['store_id', 'role']);
database/migrations/2026_05_03_211416_create_store_domains_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_211416_create_store_domains_table.php:18:            $table->enum('type', ['storefront', 'admin', 'api'])->default('storefront');
database/migrations/2026_05_03_211416_create_store_domains_table.php:23:            $table->index('store_id');
database/migrations/2026_05_03_211416_create_store_domains_table.php:24:            $table->index(['store_id', 'is_primary']);
database/migrations/2026_05_03_225413_create_shipping_zones_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_225413_create_shipping_zones_table.php:21:            $table->index('store_id');
database/migrations/2026_05_03_225422_create_tax_settings_table.php:15:            $table->foreignId('store_id')->primary()->constrained()->cascadeOnDelete();
app/Providers/AppServiceProvider.php:82:            if ($request->is('admin*')) {
app/Providers/AppServiceProvider.php:83:                return route('admin.login');
app/Providers/AppServiceProvider.php:97:            $store = app()->bound('current_store') ? app('current_store') : null;
database/migrations/2026_05_03_225427_create_discounts_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_225427_create_discounts_table.php:29:            $table->unique(['store_id', 'code']);
database/migrations/2026_05_03_225427_create_discounts_table.php:30:            $table->index('store_id');
database/migrations/2026_05_03_225427_create_discounts_table.php:31:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_225427_create_discounts_table.php:32:            $table->index(['store_id', 'type']);
database/migrations/2026_05_03_211556_create_customers_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_211556_create_customers_table.php:23:            $table->unique(['store_id', 'email']);
database/migrations/2026_05_03_211556_create_customers_table.php:24:            $table->index('store_id');
database/migrations/2026_05_03_223844_create_navigation_menus_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_223844_create_navigation_menus_table.php:21:            $table->unique(['store_id', 'handle']);
database/migrations/2026_05_03_223844_create_navigation_menus_table.php:22:            $table->index('store_id');
database/migrations/2026_05_03_213856_create_products_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213856_create_products_table.php:27:            $table->unique(['store_id', 'handle']);
database/migrations/2026_05_03_213856_create_products_table.php:28:            $table->index('store_id');
database/migrations/2026_05_03_213856_create_products_table.php:29:            $table->index(['store_id', 'status']);
database/migrations/2026_05_03_213856_create_products_table.php:30:            $table->index(['store_id', 'published_at']);
database/migrations/2026_05_03_213856_create_products_table.php:31:            $table->index(['store_id', 'vendor']);
database/migrations/2026_05_03_213856_create_products_table.php:32:            $table->index(['store_id', 'product_type']);
database/migrations/2026_05_03_211419_create_store_settings_table.php:15:            $table->foreignId('store_id')->primary()->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213901_create_inventory_items_table.php:16:            $table->foreignId('store_id')->constrained()->cascadeOnDelete();
database/migrations/2026_05_03_213901_create_inventory_items_table.php:22:            $table->index('store_id');


Output:
Chunk ID: f383ef
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 538
Output:
<?php

namespace App\Http\Middleware;

use App\Enums\StoreStatus;
use App\Models\Store;
use App\Models\StoreDomain;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpFoundation\Response;

class ResolveStore
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        $store = $request->is('admin*')
            ? $this->resolveAdminStore($request)
            : $this->resolveStorefrontStore($request);

        abort_unless($store, 404);

        app()->instance('current_store', $store);

        if (! $request->is('admin*') && $store->status === StoreStatus::Suspended) {
            abort(503);
        }

        if ($request->is('admin*') && $store->status === StoreStatus::Suspended && ! $request->isMethodSafe()) {
            abort(403);
        }

        return $next($request);
    }

    private function resolveStorefrontStore(Request $request): ?Store
    {
        $hostname = $request->getHost();
        $cacheKey = "store_domain:{$hostname}";

        $storeId = Cache::remember($cacheKey, now()->addMinutes(5), function () use ($hostname): ?int {
            return StoreDomain::query()
                ->where('hostname', $hostname)
                ->value('store_id');
        });

        return $storeId ? Store::query()->find($storeId) : null;
    }

    private function resolveAdminStore(Request $request): ?Store
    {
        $user = $request->user();

        if (! $user) {
            return null;
        }

        $storeId = $request->session()->get('current_store_id');

        if (! $storeId) {
            $storeId = $user->stores()->oldest('stores.id')->value('stores.id');

            if ($storeId) {
                $request->session()->put('current_store_id', $storeId);
            }
        }

        if (! $storeId || ! $user->stores()->whereKey($storeId)->exists()) {
            return null;
        }

        return Store::query()->find($storeId);
    }
}


Output:
Chunk ID: ab9f40
Wall time: 0.0000 seconds
Process exited with code 1
Original token count: 18
Output:
sed: app/Http/Middleware/EnsureAdminUser.php: No such file or directory


Output:
Chunk ID: e21b20
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 284
Output:
<?php

namespace App\Models\Concerns;

use App\Models\Scopes\StoreScope;
use App\Models\Store;

trait BelongsToStore
{
    public static function bootBelongsToStore(): void
    {
        static::addGlobalScope(new StoreScope);

        static::creating(function (object $model): void {
            if ($model->store_id || ! app()->bound('current_store')) {
                return;
            }

            $store = app('current_store');

            if ($store instanceof Store) {
                $model->store_id = $store->getKey();
            }
        });
    }
}
<?php

namespace App\Models\Scopes;

use App\Models\Store;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class StoreScope implements Scope
{
    public function apply(Builder $builder, Model $model): void
    {
        if (! app()->bound('current_store')) {
            return;
        }

        $store = app('current_store');

        if (! $store instanceof Store) {
            return;
        }

        $builder->where($model->qualifyColumn('store_id'), $store->getKey());
    }
}


sed -n '1,100p' bootstrap/app.php && rg -n "class CheckStoreRole" app/Http/Middleware app -g '*.php'


sed -n '1,100p' bootstrap/app.php && rg -n "class CheckStoreRole" app/Http/Middleware app -g '*.php'

rg -n 'class CheckStoreRole' app/Http/Middleware app -g '*.php'

Question: class CheckStoreRole

<?php

use App\Http\Middleware\CheckStoreRole;
use App\Http\Middleware\ResolveStore;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->alias([
            'role.check' => CheckStoreRole::class,
            'store.resolve' => ResolveStore::class,
        ]);

        $middleware->appendToGroup('storefront', [
            ResolveStore::class,
        ]);

        $middleware->appendToGroup('admin', [
            ResolveStore::class,
            CheckStoreRole::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })->create();
app/Http/Middleware/CheckStoreRole.php:11:class CheckStoreRole
app/Http/Middleware/CheckStoreRole.php:11:class CheckStoreRole