*/ class ProductModelFactory extends Factory { protected $model = ProductModel::class; private const NAMES = ['大白菜', '土豆', '西红柿', '黄瓜', '苹果', '香蕉']; private const SPECS = ['500g/袋', '10斤/箱', '散装', '25斤/袋']; private const GRADES = ['特级', '一级', '二级']; private const UNITS = ['斤', '箱', '袋']; private static int $sequence = 0; public function definition(): array { $seq = ++self::$sequence; return [ 'category_id' => 0, 'supplier_id' => 0, 'name' => self::NAMES[$seq % count(self::NAMES)] . $seq, 'spec' => self::SPECS[$seq % count(self::SPECS)], 'grade' => self::GRADES[$seq % count(self::GRADES)], 'unit' => self::UNITS[$seq % count(self::UNITS)], 'image' => '', 'sort' => $seq, 'status' => ProductModel::STATUS_ON, 'remark' => '', ]; } /** * 下架商品 */ public function off(): static { return $this->state(fn () => ['status' => ProductModel::STATUS_OFF]); } }