id = $crop->id; $dto->landId = $crop->land_id; $dto->userId = $crop->user_id; $dto->seedId = $crop->seed_id; $dto->seedName = $crop->seed->name ?? ''; $dto->plantTime = $crop->plant_time; $dto->growthStage = $crop->growth_stage->value; // $dto->growthStageName = $crop->growth_stage->name; $dto->stageStartTime = $crop->stage_start_time ? $crop->stage_start_time : null; $dto->stageEndTime = $crop->stage_end_time ? $crop->stage_end_time : null; $dto->disasters = $crop->disasters; $dto->fertilized = $crop->fertilized; $dto->finalOutputItemId = $crop->final_output_item_id; // dd($dto); return $dto; } /** * 转换为数组 * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'land_id' => $this->landId, 'user_id' => $this->userId, 'seed_id' => $this->seedId, 'seed_name' => $this->seedName, 'plant_time' => $this->plantTime, 'growth_stage' => $this->growthStage, 'growth_stage_name' => $this->growthStageName, 'stage_end_time' => $this->stageEndTime, 'disasters' => $this->disasters, 'fertilized' => $this->fertilized, 'final_output_item_id' => $this->finalOutputItemId, ]; } }