{"id":22995,"date":"2024-11-21T12:53:11","date_gmt":"2024-11-21T04:53:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22995\/"},"modified":"2024-11-21T12:53:11","modified_gmt":"2024-11-21T04:53:11","slug":"laravel%e6%95%b0%e6%8d%ae%e8%a1%a8%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22995\/","title":{"rendered":"laravel\u6570\u636e\u8868\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<p>laravel\u662f\u73b0\u4ee3php\u5f00\u53d1\u4e2d\u6700\u6d41\u884c\u7684\u6846\u67b6\u4e4b\u4e00\u3002\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u6709\u7528\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u5176\u4e2d\u6700\u91cd\u8981\u7684\u662f\u5b83\u7684orm\u3002\u53ef\u4ee5\u4f7f\u7528orm\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u8f7b\u677e\u5730\u64cd\u4f5c\u6570\u636e\u5e93\u3002\u5728laravel\u4e2d\uff0c\u4f7f\u7528orm\u5efa\u7acb\u6570\u636e\u8868\u5e76\u4e14\u8bbe\u7f6e\u6570\u636e\u8868\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528laravel\u6765\u8bbe\u7f6e\u6570\u636e\u8868\u3002<\/p>\n<p>Laravel\u6570\u636e\u5e93\u8fc1\u79fb<\/p>\n<p>\u5728Laravel\u4e2d\uff0c\u6570\u636e\u8868\u7684\u8bbe\u7f6e\u662f\u901a\u8fc7\u6570\u636e\u5e93\u8fc1\u79fb\uff08database migration\uff09\u6765\u5b8c\u6210\u7684\u3002\u6570\u636e\u5e93\u8fc1\u79fb\u662f\u4e00\u79cd\u7248\u672c\u63a7\u5236\uff0c\u7528\u4e8e\u7ba1\u7406\u6570\u636e\u8868\u7684\u7ed3\u6784\u53d8\u5316\u3002\u6bcf\u4e00\u4e2a\u8fc1\u79fb\u90fd\u63cf\u8ff0\u4e86\u6570\u636e\u5e93\u6a21\u5f0f\u7684\u53d8\u5316\u3002\u6bcf\u4e2a\u7248\u672c\u63a7\u5236\u8fc1\u79fb\u90fd\u5448\u73b0\u4e86\u4e00\u6b21\u6570\u636e\u5e93\u5347\u7ea7\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u56de\u5230\u4e4b\u524d\u7684\u7248\u672c\u6216\u8005\u5347\u7ea7\u5230\u8f83\u65b0\u7684\u7248\u672c\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0cLaravel\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u547d\u4ee4\u884c\u529f\u80fd\u6765\u521b\u5efa\u548c\u7ba1\u7406\u8fc1\u79fb\u3002\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5411\u6570\u636e\u5e93\u6dfb\u52a0\u6216\u5220\u9664\u8868\u683c\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u4e0d\u5fc5\u624b\u52a8\u7f16\u5199SQL\u4ee3\u7801\u3002<\/p>\n<p>Laravel\u8fc1\u79fb\u7684\u521b\u5efa<\/p>\n<p>\u9996\u5148\uff0c\u5728Laravel\u4e2d\u521b\u5efa\u8fc1\u79fb\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u8fc1\u79fb\uff1a<\/p>\n<pre>php artisan make:migration create_users_table<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8fc1\u79fb\uff0c\u540d\u4e3a\u201ccreate_users_table\u201d\u3002\u8fc1\u79fb\u5c06\u4fdd\u5b58\u5728\u201cdatabase\/migrations\u201d\u76ee\u5f55\u4e0b\u3002\u8fd9\u4e2a\u76ee\u5f55\u5c31\u662fLaravel\u6846\u67b6\u81ea\u5e26\u7684\u6570\u636e\u5e93\u8fc1\u79fb\u76ee\u5f55\u3002<\/p>\n<p>\u6253\u5f00\u521a\u521b\u5efa\u7684\u8fc1\u79fb\u3002\u4f60\u5c06\u770b\u5230\u4e00\u4e2a\u7a7a\u7684\u201cup\u201d\u65b9\u6cd5\uff0c\u8fd9\u662f\u5f53\u4f60\u8fc1\u79fb\u65f6\u6267\u884c\u7684\u4ee3\u7801\u3002\u4e0b\u9762\u662f\u8fd9\u4e2a\u65b9\u6cd5\u7684\u7b80\u5355\u7684\u7ed3\u6784\uff1a<\/p>\n<pre>public function up()\n{\n    \/\/\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u7528\u4e8e\u521b\u5efa\u6570\u636e\u8868\u7684\u4ee3\u7801\u3002\u6211\u4eec\u5c06\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\u89e3\u91ca\u3002<\/p>\n<p>Laravel\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u5728Laravel\u4e2d\uff0c\u6709\u591a\u79cd\u6570\u636e\u7c7b\u578b\u53ef\u4f9b\u9009\u62e9\uff0c\u7528\u4e8e\u63cf\u8ff0\u6570\u636e\u8868\u5217\u7684\u7c7b\u578b\u3002\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4e00\u4e9b\u53ef\u7528\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>1.\u81ea\u589eID<\/p>\n<p>$table-&gt;bigIncrements(&#8216;id&#8217;)<\/p>\n<p>2.\u6574\u6570<\/p>\n<p>$table-&gt;integer(&#8216;age&#8217;)<\/p>\n<p>3.\u957f\u6574\u6570<\/p>\n<p>$table-&gt;bigInteger(&#8216;views&#8217;)<\/p>\n<p>4.\u5c0f\u6570<\/p>\n<p>$table-&gt;decimal(&#8216;price&#8217;, 5, 2)<\/p>\n<p>5.\u5b57\u7b26\u4e32<\/p>\n<p>$table-&gt;string(&#8216;name&#8217;)<\/p>\n<p>6.\u957f\u6587\u672c<\/p>\n<p>$table-&gt;longText(&#8216;description&#8217;)<\/p>\n<p>7.\u65e5\u671f<\/p>\n<p>$table-&gt;date(&#8216;dob&#8217;)<\/p>\n<p>8.\u65e5\u671f\u65f6\u95f4<\/p>\n<p>$table-&gt;dateTime(&#8216;published_at&#8217;)<\/p>\n<p>9.\u5e03\u5c14<\/p>\n<p>$table-&gt;boolean(&#8216;is_active&#8217;)<\/p>\n<p>10.JSON<\/p>\n<p>$table-&gt;json(&#8216;options&#8217;)<\/p>\n<p>11.\u65f6\u95f4\u6233<\/p>\n<p>$table-&gt;timestamps()<\/p>\n<p>Laravel\u6570\u636e\u8868\u7684\u8bbe\u7f6e<\/p>\n<p>\u4f7f\u7528\u4e0a\u9762\u7684\u547d\u4ee4\u521b\u5efa\u8fc1\u79fb\u5e76\u6253\u5f00\u201cup\u201d\u65b9\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u9700\u8981\u8bbe\u7f6e\u6570\u636e\u8868\u7684\u540d\u79f0\u3001\u5217\u4ee5\u53ca\u5b83\u4eec\u7684\u7c7b\u578b\u548c\u5176\u4ed6\u7ec6\u8282\u3002\u4e0b\u9762\u662f\u5982\u4f55\u8bbe\u7f6e\u4e00\u4e2a\u540d\u4e3a\u201cusers\u201d\u7684\u6570\u636e\u8868\uff1a<\/p>\n<pre>public function up()\n{\n    Schema::create('users', function (Blueprint $table) {\n        $table-&amp;gt;bigIncrements('id');\n        $table-&amp;gt;string('name');\n        $table-&amp;gt;string('email')-&amp;gt;unique();\n        $table-&amp;gt;timestamp('email_verified_at')-&amp;gt;nullable();\n        $table-&amp;gt;string('password');\n        $table-&amp;gt;rememberToken();\n        $table-&amp;gt;timestamps();\n    });\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528\u201cSchema::create\u201d\u65b9\u6cd5\u6765\u521b\u5efa\u6570\u636e\u8868\u3002\u5728\u8c03\u7528\u201cSchema::create\u201d\u65b9\u6cd5\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4f20\u9012\u6570\u636e\u8868\u540d\u79f0\u548c\u4e00\u4e2a\u56de\u8c03\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u56de\u8c03\u65b9\u6cd5\u7528\u4e8e\u63cf\u8ff0\u8fd9\u4e2a\u6570\u636e\u8868\u7684\u5217\u548c\u5176\u4ed6\u7ec6\u8282\u3002\u5728\u56de\u8c03\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528\u201cBlueprint\u201d\u7c7b\u521b\u5efa\u5217\u3002\u5982\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u79f0\u4e3a\u201cid\u201d\u7684\u81ea\u589e\u5217\uff0c\u5e76\u4e14\u8fd9\u4e2a\u5217\u662f\u6b64\u6570\u636e\u8868\u7684\u4e3b\u952e\u3002\u5217\u7684\u540d\u79f0\u4f7f\u7528\u5b57\u7b26\u4e32\u6765\u8868\u793a\uff0c\u5217\u7684\u7c7b\u578b\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u5217\u51fa\u7684\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u8c03\u7528\u201cSchema::create\u201d\u65b9\u6cd5\u5c06\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cusers\u201d\u7684\u8868\u3002\u5982\u679c\u6570\u636e\u8868\u5df2\u7ecf\u5b58\u5728\uff0c\u4f60\u4ecd\u7136\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u6765\u5411\u5b83\u6dfb\u52a0\u66f4\u591a\u7684\u5217\u6216\u66f4\u6539\u5b83\u7684\u7ed3\u6784\u3002\u4e3a\u4e86\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\uff0c\u4f60\u9700\u8981\u4f7f\u7528\u201cSchema::table\u201d\u65b9\u6cd5\uff0c\u5e76\u5728\u56de\u8c03\u51fd\u6570\u4e2d\u6307\u5b9a\u66f4\u6539\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5c06\u5411\u540d\u4e3a\u201cusers\u201d\u7684\u6570\u636e\u8868\u6dfb\u52a0\u4e00\u4e2a\u540d\u4e3a\u201cphone\u201d\u7684\u5217\uff1a<\/p>\n<pre>public function up()\n{\n    Schema::table('users', function (Blueprint $table) {\n        $table-&amp;gt;string('phone')-&amp;gt;after('email');\n    });\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528\u201cSchema::table\u201d\u65b9\u6cd5\u6765\u66f4\u6539\u540d\u4e3a\u201cusers\u201d\u7684\u6570\u636e\u8868\u3002\u66f4\u6539\u7684\u8be6\u60c5\u662f\u8ba9\u8fc1\u79fb\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cphone\u201d\u7684\u5217\uff0c\u5e76\u4e14\u5c06\u5176\u653e\u7f6e\u5728\u201cemail\u201d\u5217\u4e4b\u540e\u3002<\/p>\n<p>Laravel\u8fc1\u79fb\u7684\u8fd0\u884c<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5df2\u7ecf\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u6570\u636e\u8868\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u8fd0\u884c\u8fc1\u79fb\u5e76\u5c06\u66f4\u6539\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e2d\u3002\u8981\u8fd0\u884c\u8fc1\u79fb\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>php artisan migrate<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u8fd0\u884c\u6240\u6709\u5c1a\u672a\u8fd0\u884c\u7684\u8fc1\u79fb\u3002<\/p>\n<p>Laravel\u8fc1\u79fb\u7684\u56de\u6eda<\/p>\n<p>Laravel\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u95ee\u9898\u56de\u6eda\u547d\u4ee4\uff0c\u5b83\u7528\u4e8e\u64a4\u56de\u4e4b\u524d\u8fd0\u884c\u7684\u8fc1\u79fb\u3002\u5728\u64a4\u56de\u8fc1\u79fb\u65f6\uff0cLaravel\u4f1a\u81ea\u52a8\u6062\u590d\u66f4\u6539\u524d\u7248\u672c\u7684\u6570\u636e\u8868\u7ed3\u6784\u3002\u8981\u56de\u6eda\u4e00\u4e2a\u8fc1\u79fb\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>php artisan migrate:rollback<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u56de\u6eda\u6700\u540e\u4e00\u4e2a\u8fc1\u79fb\u3002\u5982\u679c\u4f60\u60f3\u64a4\u56de\u66f4\u591a\u7684\u8fc1\u79fb\uff0c\u8bf7\u4f7f\u7528\u201c&#8211;step\u201d\u53c2\u6570\u548c\u6570\u5b57\u6765\u6307\u5b9a\u8981\u56de\u6eda\u7684\u8fc1\u79fb\u6570\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>php artisan migrate:rollback --step=2<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u56de\u6eda\u6700\u540e\u4e24\u4e2a\u8fc1\u79fb\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>Laravel\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u4fbf\u65b9\u6cd5\u6765\u7ba1\u7406\u6570\u636e\u5e93\u7ed3\u6784\u53d8\u5316\u3002\u4f7f\u7528\u6570\u636e\u5e93\u8fc1\u79fb\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5411Laravel\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u6216\u5220\u9664\u6570\u636e\u8868\uff0c\u8fd9\u662f\u4e3a\u4fdd\u6301\u826f\u597d\u7684\u7248\u672c\u63a7\u5236\u800c\u5fc5\u9700\u7684\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5728Laravel\u4e2d\u5982\u4f55\u521b\u5efa\u548c\u8bbe\u7f6e\u6570\u636e\u8868\uff0c\u4ee5\u53ca\u5982\u4f55\u8fd0\u884c\u548c\u56de\u6eda\u8fc1\u79fb\u3002\u5982\u679c\u4f60\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u5c06\u80fd\u591f\u5728Laravel\u4e2d\u8f7b\u677e\u5730\u521b\u5efa\u548c\u7ba1\u7406\u6570\u636e\u8868\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel\u6570\u636e\u8868\u600e\u4e48\u8bbe\u7f6e\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>laravel\u662f\u73b0\u4ee3php\u5f00\u53d1\u4e2d\u6700\u6d41\u884c\u7684\u6846\u67b6\u4e4b\u4e00\u3002\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u6709\u7528\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u5176\u4e2d\u6700\u91cd\u8981\u7684\u662f\u5b83\u7684orm\u3002\u53ef\u4ee5\u4f7f\u7528orm\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u8f7b\u677e\u5730\u64cd\u4f5c\u6570\u636e\u5e93\u3002\u5728laravel\u4e2d\uff0c\u4f7f\u7528orm\u5efa\u7acb\u6570\u636e\u8868\u5e76\u4e14\u8bbe\u7f6e\u6570\u636e\u8868\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4f7f\u7528laravel\u6765\u8bbe\u7f6e\u6570\u636e\u8868\u3002 Laravel\u6570\u636e\u5e93\u8fc1\u79fb \u5728Laravel\u4e2d\uff0c\u6570\u636e\u8868\u7684\u8bbe\u7f6e\u662f\u901a\u8fc7\u6570\u636e\u5e93\u8fc1\u79fb\uff08database migration\uff09\u6765\u5b8c\u6210\u7684\u3002\u6570\u636e\u5e93\u8fc1\u79fb\u662f\u4e00\u79cd\u7248\u672c\u63a7\u5236\uff0c\u7528\u4e8e\u7ba1\u7406\u6570\u636e\u8868\u7684\u7ed3\u6784\u53d8\u5316\u3002\u6bcf\u4e00\u4e2a\u8fc1\u79fb\u90fd\u63cf\u8ff0\u4e86\u6570\u636e\u5e93\u6a21\u5f0f\u7684\u53d8\u5316\u3002\u6bcf\u4e2a\u7248\u672c\u63a7\u5236\u8fc1\u79fb\u90fd\u5448\u73b0\u4e86\u4e00\u6b21\u6570\u636e\u5e93\u5347\u7ea7\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u56de\u5230\u4e4b\u524d\u7684\u7248\u672c\u6216\u8005\u5347\u7ea7\u5230\u8f83\u65b0\u7684\u7248\u672c\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0cLaravel\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u547d\u4ee4\u884c\u529f\u80fd\u6765\u521b\u5efa\u548c\u7ba1\u7406\u8fc1\u79fb\u3002\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5411\u6570\u636e\u5e93\u6dfb\u52a0\u6216\u5220\u9664\u8868\u683c\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u4e0d\u5fc5\u624b\u52a8\u7f16\u5199SQL\u4ee3\u7801\u3002 Laravel\u8fc1\u79fb\u7684\u521b\u5efa \u9996\u5148\uff0c\u5728Laravel\u4e2d\u521b\u5efa\u8fc1\u79fb\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u8fc1\u79fb\uff1a php artisan make:migration create_users_table \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e2a\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8fc1\u79fb\uff0c\u540d\u4e3a\u201ccreate_users_table\u201d\u3002\u8fc1\u79fb\u5c06\u4fdd\u5b58\u5728\u201cdatabase\/migrations\u201d\u76ee\u5f55\u4e0b\u3002\u8fd9\u4e2a\u76ee\u5f55\u5c31\u662fLaravel\u6846\u67b6\u81ea\u5e26\u7684\u6570\u636e\u5e93\u8fc1\u79fb\u76ee\u5f55\u3002 \u6253\u5f00\u521a\u521b\u5efa\u7684\u8fc1\u79fb\u3002\u4f60\u5c06\u770b\u5230\u4e00\u4e2a\u7a7a\u7684\u201cup\u201d\u65b9\u6cd5\uff0c\u8fd9\u662f\u5f53\u4f60\u8fc1\u79fb\u65f6\u6267\u884c\u7684\u4ee3\u7801\u3002\u4e0b\u9762\u662f\u8fd9\u4e2a\u65b9\u6cd5\u7684\u7b80\u5355\u7684\u7ed3\u6784\uff1a public function up() { \/\/ } \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u7528\u4e8e\u521b\u5efa\u6570\u636e\u8868\u7684\u4ee3\u7801\u3002\u6211\u4eec\u5c06\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\u89e3\u91ca\u3002 Laravel\u6570\u636e\u7c7b\u578b \u5728Laravel\u4e2d\uff0c\u6709\u591a\u79cd\u6570\u636e\u7c7b\u578b\u53ef\u4f9b\u9009\u62e9\uff0c\u7528\u4e8e\u63cf\u8ff0\u6570\u636e\u8868\u5217\u7684\u7c7b\u578b\u3002\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u4e00\u4e9b\u53ef\u7528\u7684\u6570\u636e\u7c7b\u578b\u3002 1.\u81ea\u589eID $table-&gt;bigIncrements(&#8216;id&#8217;) 2.\u6574\u6570 $table-&gt;integer(&#8216;age&#8217;) 3.\u957f\u6574\u6570 $table-&gt;bigInteger(&#8216;views&#8217;) 4.\u5c0f\u6570 $table-&gt;decimal(&#8216;price&#8217;, 5, 2) 5.\u5b57\u7b26\u4e32 $table-&gt;string(&#8216;name&#8217;) 6.\u957f\u6587\u672c $table-&gt;longText(&#8216;description&#8217;) 7.\u65e5\u671f $table-&gt;date(&#8216;dob&#8217;) 8.\u65e5\u671f\u65f6\u95f4 $table-&gt;dateTime(&#8216;published_at&#8217;) 9.\u5e03\u5c14 $table-&gt;boolean(&#8216;is_active&#8217;) 10.JSON $table-&gt;json(&#8216;options&#8217;) 11.\u65f6\u95f4\u6233 $table-&gt;timestamps() Laravel\u6570\u636e\u8868\u7684\u8bbe\u7f6e \u4f7f\u7528\u4e0a\u9762\u7684\u547d\u4ee4\u521b\u5efa\u8fc1\u79fb\u5e76\u6253\u5f00\u201cup\u201d\u65b9\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u9700\u8981\u8bbe\u7f6e\u6570\u636e\u8868\u7684\u540d\u79f0\u3001\u5217\u4ee5\u53ca\u5b83\u4eec\u7684\u7c7b\u578b\u548c\u5176\u4ed6\u7ec6\u8282\u3002\u4e0b\u9762\u662f\u5982\u4f55\u8bbe\u7f6e\u4e00\u4e2a\u540d\u4e3a\u201cusers\u201d\u7684\u6570\u636e\u8868\uff1a public function up() { Schema::create(&#8216;users&#8217;, function [&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-22995","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22995","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=22995"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22995\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}