{"id":28409,"date":"2024-11-24T09:27:17","date_gmt":"2024-11-24T01:27:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28409\/"},"modified":"2024-11-24T09:27:17","modified_gmt":"2024-11-24T01:27:17","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-laravel-%e4%b8%ad%e5%a4%84%e7%90%86%e5%a4%a7%e5%9e%8b%e6%95%b0%e6%8d%ae%e9%9b%86%e8%80%8c%e4%b8%8d%e8%80%97%e5%b0%bd%e5%86%85%e5%ad%98","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28409\/","title":{"rendered":"\u5982\u4f55\u5728 Laravel \u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u800c\u4e0d\u8017\u5c3d\u5185\u5b58"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173165442769900.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Laravel \u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u800c\u4e0d\u8017\u5c3d\u5185\u5b58\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Laravel \u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u800c\u4e0d\u8017\u5c3d\u5185\u5b58\u63d2\u56fe\" \/><\/p>\n<h3> \u5982\u4f55\u5728  \u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u800c\u4e0d\u8017\u5c3d\u5185\u5b58 <\/h3>\n<p>\u5728 laravel \u4e2d\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u5e94\u7528\u7a0b\u5e8f\u5185\u5b58\u4e0d\u8db3\u7b49\u95ee\u9898\u3002\u5f53\u5c1d\u8bd5\u4e00\u6b21\u5c06\u6570\u5343\uff08\u751a\u81f3\u6570\u767e\u4e07\uff09\u6761\u8bb0\u5f55\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u65f6\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002\u7136\u800c\uff0claravel \u63d0\u4f9b\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u65b9\u6cd5\u6765\u5e2e\u52a9\u60a8\u4ee5\u8f83\u5c0f\u7684\u5757\u5904\u7406\u6570\u636e\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u5e76\u4f7f\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u5f97\u66f4\u5feb\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 <strong>chunk()<\/strong>\u3001<strong>chunkbyid()<\/strong> \u548c <strong>lazy collections<\/strong> \u5728 laravel \u4e2d\u9ad8\u6548\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<\/p>\n<h3> chunk() \u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f <\/h3>\n<p>laravel \u4e2d\u7684 chunk() \u65b9\u6cd5\u5141\u8bb8\u60a8\u4e00\u6b21\u68c0\u7d22\u4e00\u5c0f\u90e8\u5206\u8bb0\u5f55\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u5185\u5bb9\u3002\u5f53\u60a8\u9700\u8981\u5904\u7406\u5927\u91cf\u8bb0\u5f55\u4f46\u53c8\u60f3\u907f\u514d\u4f7f\u7528\u8fc7\u591a\u5185\u5b58\u65f6\uff0c\u6b64\u65b9\u6cd5\u5f88\u6709\u7528\u3002<\/p>\n<h4> \u793a\u4f8b\uff1a\u4f7f\u7528 chunk() \u6279\u91cf\u5904\u7406\u6570\u636e <\/h4>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u8ba2\u5355\u8868\uff0c\u5e76\u4e14\u60a8\u60f3\u8981\u5c06\u6bcf\u4e2a\u8ba2\u5355\u7684\u72b6\u6001\u66f4\u65b0\u4e3a\u201c\u5df2\u5904\u7406\u201d\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 chunk() \u4e00\u6b21\u52a0\u8f7d 100 \u4e2a\u8ba2\u5355\u5e76\u4ee5\u8f83\u5c0f\u7684\u6279\u6b21\u5904\u7406\u5b83\u4eec\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u5c06\u6240\u6709\u8ba2\u5355\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/p>\n<pre>use appmodelsorder;\n\norder::chunk(100, function ($orders) {\n    foreach ($orders as $order) {\n        \/\/ process each order\n        $order-&gt;update(['status' =&gt; 'processed']);\n    }\n});\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> 100 \u662f\u60a8\u8981\u4e00\u6b21\u5904\u7406\u7684\u8bb0\u5f55\u6570\u3002<\/li>\n<li>\u5c06\u4e3a 100 \u6761\u8bb0\u5f55\u7684\u6bcf\u4e2a\u201c\u5757\u201d\u8c03\u7528\u56de\u8c03\u51fd\u6570\u3002<\/li>\n<li>\u5904\u7406\u5b8c\u524d 100 \u4e2a\u540e\uff0c\u5c06\u7ee7\u7eed\u5904\u7406\u4e0b\u4e00\u6279\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002<\/li>\n<\/ul>\n<h4> \u4f7f\u7528 chunk()\uff1f <\/h4>\n<ul>\n<li> <strong>\u8282\u7701\u5185\u5b58<\/strong>\uff1alaravel \u4e0d\u4f1a\u4e00\u6b21\u52a0\u8f7d\u6240\u6709\u8bb0\u5f55\uff0c\u800c\u662f\u53ea\u52a0\u8f7d\u4e00\u5c0f\u90e8\u5206\u8bb0\u5f55\uff08\u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\u4e3a 100 \u6761\uff09\uff0c\u4ece\u800c\u4fdd\u6301\u8f83\u4f4e\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u3002<\/li>\n<li> <strong>\u9ad8\u6548\u5904\u7406<\/strong>\uff1a\u8fd9\u4f7f\u5f97\u60a8\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\uff0c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u5d29\u6e83\u6216\u53d8\u6162\u3002<\/li>\n<\/ul>\n<h3> chunkbyid() \u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f <\/h3>\n<p>chunkbyid() \u65b9\u6cd5\u4e0e chunk() \u7c7b\u4f3c\uff0c\u4f46\u5728\u5904\u7406\u8bb0\u5f55\u65f6\u66f4\u65b0\u8bb0\u5f55\u65f6\u6548\u679c\u66f4\u597d\u3002\u6b64\u65b9\u6cd5\u53ef\u786e\u4fdd\u59cb\u7ec8\u901a\u8fc7 id \u5217\u4ee5\u4e00\u81f4\u7684\u987a\u5e8f\u68c0\u7d22\u8bb0\u5f55\uff0c\u4ece\u800c\u66f4\u5b89\u5168\u5730\u66f4\u65b0\u6570\u636e\u800c\u4e0d\u4f1a\u4e22\u5931\u4efb\u4f55\u8bb0\u5f55\u3002<\/p>\n<h4> \u793a\u4f8b\uff1a\u4f7f\u7528 chunkbyid() \u8fdb\u884c\u4e00\u81f4\u66f4\u65b0 <\/h4>\n<p>\u5047\u8bbe\u60a8\u60f3\u8981\u66f4\u65b0\u8ba2\u5355\u7684\u72b6\u6001\uff0c\u4f46\u60a8\u8fd8\u9700\u8981\u786e\u4fdd\u8ba2\u5355 id \u6309\u987a\u5e8f\u5904\u7406\u3002\u4f7f\u7528 chunkbyid() \u53ef\u786e\u4fdd\u8ba2\u5355\u4e0d\u4f1a\u88ab\u8df3\u8fc7\u6216\u5904\u7406\u4e24\u6b21\uff0c\u5373\u4f7f\u60a8\u6b63\u5728\u66f4\u65b0\u5b83\u4eec\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n<pre>use appmodelsorder;\n\norder::chunkbyid(100, function ($orders) {\n    foreach ($orders as $order) {\n        \/\/ update each order's status\n        $order-&gt;update(['status' =&gt; 'processed']);\n    }\n}, 'id');\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>chunkbyid(100) \u65b9\u6cd5\u786e\u4fdd\u4ee5 100 \u6761\u4e3a\u6279\u6b21\u68c0\u7d22\u8bb0\u5f55\uff0c\u4f46\u4ec5\u83b7\u53d6 id \u5927\u4e8e\u4e0a\u4e00\u6279\u7684\u8ba2\u5355\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u4e22\u5931\u8bb0\u5f55\u3002<\/li>\n<li> \u201cid\u201d\u662f\u7528\u4e8e\u786e\u5b9a\u8bb0\u5f55\u5904\u7406\u987a\u5e8f\u7684\u5217\u3002<\/li>\n<\/ul>\n<h4> \u4e3a\u4ec0\u4e48\u4f7f\u7528 chunkbyid()\uff1f <\/h4>\n<ul>\n<li> <strong>\u4e00\u81f4\u6027<\/strong>\uff1a\u5f53\u60a8\u5728\u5904\u7406\u8bb0\u5f55\u7684\u540c\u65f6\u66f4\u65b0\u8bb0\u5f55\u65f6\uff0cchunkbyid() \u6709\u52a9\u4e8e\u4fdd\u6301\u6570\u636e\u4e00\u81f4\uff0c\u9632\u6b62\u8bb0\u5f55\u88ab\u8df3\u8fc7\u6216\u5904\u7406\u4e24\u6b21\u3002<\/li>\n<li> <strong>\u5bf9\u4e8e\u5927\u6570\u636e\u66f4\u65b0\u6765\u8bf4\u662f\u5b89\u5168\u7684<\/strong>\uff1a\u5f53\u60a8\u5728\u6b64\u8fc7\u7a0b\u4e2d\u4fee\u6539\u8bb0\u5f55\uff08\u4f8b\u5982\u66f4\u65b0\u5176\u72b6\u6001\uff09\u65f6\uff0c\u8fd9\u662f\u7406\u60f3\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<h3> \u4f7f\u7528\u60f0\u6027\u96c6\u5408\u8fdb\u884c\u4e00\u5bf9\u4e00\u5904\u7406 <\/h3>\n<p>chunk() \u548c chunkbyid() \u6279\u91cf\u5904\u7406\u8bb0\u5f55\uff0c<strong>lazy collections<\/strong> \u5141\u8bb8\u60a8\u4e00\u6761\u4e00\u6761\u5730\u5904\u7406\u8bb0\u5f55\u3002\u5f53\u60a8\u60f3\u8981\u5728\u68c0\u7d22\u65f6\u5904\u7406\u6bcf\u6761\u8bb0\u5f55\u800c\u4e0d\u5360\u7528\u592a\u591a\u5185\u5b58\u65f6\uff0c\u8fd9\u7279\u522b\u6709\u7528\u3002<\/p>\n<h4> \u793a\u4f8b\uff1a\u4f7f\u7528\u60f0\u6027\u96c6\u5408 <\/h4>\n<p>\u5982\u679c\u60a8\u4e00\u6b21\u53ea\u9700\u8981\u5904\u7406\u4e00\u6761\u8bb0\u5f55\uff0clazy collections \u53ef\u80fd\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u8fd9\u662f\u6211\u4eec\u5355\u72ec\u5904\u7406\u6bcf\u4e2a\u8ba2\u5355\u8bb0\u5f55\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>use AppModelsOrder;\n\nforeach (Order::lazy() as $order) {\n    \/\/ Process each order one by one\n    $order-&gt;update(['status' =&gt; 'processed']);\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u4f7f\u7528lazy()\uff0c\u6bcf\u4e2a\u8ba2\u5355\u4e00\u6b21\u5904\u7406\u4e00\u4e2a\uff0c\u800c\u4e0d\u4f1a\u5c06\u6574\u4e2a\u6570\u636e\u96c6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/li>\n<li>\u5f53\u60a8\u5904\u7406\u975e\u5e38\u5927\u7684\u6570\u636e\u96c6\u65f6\uff0c\u8fd9\u975e\u5e38\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u540c\u65f6\u5c06\u6240\u6709\u8bb0\u5f55\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u3002<\/li>\n<\/ul>\n<h4> \u4e3a\u4ec0\u4e48\u4f7f\u7528\u60f0\u6027\u96c6\u5408\uff1f <\/h4>\n<ul>\n<li> <strong>\u5185\u5b58\u4f7f\u7528\u91cf\u975e\u5e38\u4f4e<\/strong>\uff1a\u6bcf\u6761\u8bb0\u5f55\u5728\u68c0\u7d22\u65f6\u90fd\u4f1a\u8fdb\u884c\u5904\u7406\uff0c\u56e0\u6b64\u5185\u5b58\u4f7f\u7528\u91cf\u4fdd\u6301\u5728\u6700\u4f4e\u6c34\u5e73\u3002<\/li>\n<li> <strong>\u975e\u5e38\u9002\u5408\u5927\u578b\u6570\u636e\u96c6<\/strong>\uff1a\u5982\u679c\u60a8\u9700\u8981\u5904\u7406\u5927\u91cf\u8bb0\u5f55\u5e76\u5e0c\u671b\u907f\u514d\u9ad8\u5185\u5b58\u4f7f\u7528\uff0c\u60f0\u6027\u96c6\u5408\u662f\u60a8\u6700\u597d\u7684\u670b\u53cb\u3002<\/li>\n<\/ul>\n<h3> \u4f55\u65f6\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5 <\/h3>\n<ul>\n<li> <strong>\u5f53\u60a8\u60f3\u8981\u6279\u91cf\u5904\u7406\u56fa\u5b9a\u5927\u5c0f\u7684\u8bb0\u5f55\uff08\u4f8b\u5982 100 \u6216 200\uff09\u65f6\uff0c\u8bf7\u4f7f\u7528 chunk()<\/strong>\uff0c\u4f46\u4e0d\u9700\u8981\u62c5\u5fc3\u8bb0\u5f55\u7684\u987a\u5e8f\u3002<\/li>\n<li> <strong>\u5f53\u9700\u8981\u6279\u91cf\u5904\u7406\u8bb0\u5f55\u4f46\u53c8\u9700\u8981\u4fdd\u8bc1\u66f4\u65b0\u65f6\u7684\u4e00\u81f4\u6027\u65f6\uff0c\u8bf7\u4f7f\u7528 chunkbyid()<\/strong>\u3002\u6b64\u65b9\u6cd5\u4fdd\u8bc1\u4e0d\u4f1a\u8df3\u8fc7\u4efb\u4f55\u8bb0\u5f55\u6216\u5904\u7406\u4e24\u6b21\u3002<\/li>\n<li> <strong>\u5f53\u60a8\u9700\u8981\u4e00\u6b21\u5904\u7406\u4e00\u4e2a\u8bb0\u5f55\u5e76\u5e0c\u671b\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11\u5185\u5b58\u4f7f\u7528\u65f6\uff0c\u8bf7\u4f7f\u7528\u60f0\u6027\u96c6\u5408<\/strong>\u3002<\/li>\n<\/ul>\n<h3> \u7ed3\u8bba\uff1alaravel \u4e2d\u7684\u9ad8\u6548\u6570\u636e\u5904\u7406 <\/h3>\n<p>laravel \u63d0\u4f9b\u4e86\u4e00\u4e9b\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\u6765\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\uff0c\u800c\u4e0d\u4f1a\u9047\u5230\u5185\u5b58\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u6211\u4eec\u6240\u5b66\u5230\u7684\u5185\u5bb9\u7684\u5feb\u901f\u56de\u987e\uff1a<\/p>\n<ul>\n<li> <strong>chunk()<\/strong>\uff1a\u5c0f\u6279\u91cf\u5904\u7406\u8bb0\u5f55\u4ee5\u8282\u7701\u5185\u5b58\u3002<\/li>\n<li> <strong>chunkbyid()<\/strong>\uff1a\u6279\u91cf\u5904\u7406\u8bb0\u5f55\uff0c\u540c\u65f6\u786e\u4fdd\u4e00\u81f4\u6027\uff08\u975e\u5e38\u9002\u5408\u66f4\u65b0\uff09\u3002<\/li>\n<li> <strong>\u60f0\u6027\u96c6\u5408<\/strong>\uff1a\u4e00\u6b21\u5904\u7406\u4e00\u4e2a\u8bb0\u5f55\uff0c\u975e\u5e38\u9002\u5408\u4ee5\u6700\u5c11\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd\u60a8\u7684 laravel \u5e94\u7528\u7a0b\u5e8f\u6709\u6548\u5730\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\uff0c\u5373\u4f7f\u5728\u5904\u7406\u6570\u767e\u4e07\u6761\u8bb0\u5f55\u65f6\u4e5f\u662f\u5982\u6b64\u3002\u65e0\u8bba\u60a8\u9700\u8981\u5904\u7406\u591a\u5c11\u6570\u636e\uff0c\u8fd9\u4e9b\u6280\u672f\u5bf9\u4e8e\u6784\u5efa\u6027\u80fd\u826f\u597d\u7684\u53ef\u6269\u5c55\u5e94\u7528\u7a0b\u5e8f\u90fd\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Laravel \u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u800c\u4e0d\u8017\u5c3d\u5185\u5b58\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 \u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u800c\u4e0d\u8017\u5c3d\u5185\u5b58 \u5728 laravel \u4e2d\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u5e94\u7528\u7a0b\u5e8f\u5185\u5b58\u4e0d\u8db3\u7b49\u95ee\u9898\u3002\u5f53\u5c1d\u8bd5\u4e00\u6b21\u5c06\u6570\u5343\uff08\u751a\u81f3\u6570\u767e\u4e07\uff09\u6761\u8bb0\u5f55\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u65f6\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002\u7136\u800c\uff0claravel \u63d0\u4f9b\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u65b9\u6cd5\u6765\u5e2e\u52a9\u60a8\u4ee5\u8f83\u5c0f\u7684\u5757\u5904\u7406\u6570\u636e\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u5e76\u4f7f\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u5f97\u66f4\u5feb\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 chunk()\u3001chunkbyid() \u548c lazy collections \u5728 laravel \u4e2d\u9ad8\u6548\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002 chunk() \u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f laravel \u4e2d\u7684 chunk() \u65b9\u6cd5\u5141\u8bb8\u60a8\u4e00\u6b21\u68c0\u7d22\u4e00\u5c0f\u90e8\u5206\u8bb0\u5f55\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u5185\u5bb9\u3002\u5f53\u60a8\u9700\u8981\u5904\u7406\u5927\u91cf\u8bb0\u5f55\u4f46\u53c8\u60f3\u907f\u514d\u4f7f\u7528\u8fc7\u591a\u5185\u5b58\u65f6\uff0c\u6b64\u65b9\u6cd5\u5f88\u6709\u7528\u3002 \u793a\u4f8b\uff1a\u4f7f\u7528 chunk() \u6279\u91cf\u5904\u7406\u6570\u636e \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u8ba2\u5355\u8868\uff0c\u5e76\u4e14\u60a8\u60f3\u8981\u5c06\u6bcf\u4e2a\u8ba2\u5355\u7684\u72b6\u6001\u66f4\u65b0\u4e3a\u201c\u5df2\u5904\u7406\u201d\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 chunk() \u4e00\u6b21\u52a0\u8f7d 100 \u4e2a\u8ba2\u5355\u5e76\u4ee5\u8f83\u5c0f\u7684\u6279\u6b21\u5904\u7406\u5b83\u4eec\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u5c06\u6240\u6709\u8ba2\u5355\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002 use appmodelsorder; order::chunk(100, function ($orders) { foreach ($orders as $order) { \/\/ process each order $order-&gt;update([&#8216;status&#8217; =&gt; &#8216;processed&#8217;]); } }); \u767b\u5f55\u540e\u590d\u5236 100 \u662f\u60a8\u8981\u4e00\u6b21\u5904\u7406\u7684\u8bb0\u5f55\u6570\u3002 \u5c06\u4e3a 100 \u6761\u8bb0\u5f55\u7684\u6bcf\u4e2a\u201c\u5757\u201d\u8c03\u7528\u56de\u8c03\u51fd\u6570\u3002 \u5904\u7406\u5b8c\u524d 100 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-28409","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28409"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28409\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}