{"id":24819,"date":"2024-11-21T16:32:54","date_gmt":"2024-11-21T08:32:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24819\/"},"modified":"2024-11-21T16:32:54","modified_gmt":"2024-11-21T08:32:54","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8laravel%e5%bc%80%e5%8f%91%e4%b8%80%e4%b8%aa%e5%9c%a8%e7%ba%bf%e5%8c%bb%e7%96%97%e5%b9%b3%e5%8f%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24819\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Laravel\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u533b\u7597\u5e73\u53f0"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169889761734091.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528Laravel\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u533b\u7597\u5e73\u53f0\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528Laravel\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u533b\u7597\u5e73\u53f0\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u4f7f\u7528Laravel\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u533b\u7597\u5e73\u53f0<\/p>\n<p>\u7b80\u4ecb\uff1a<br \/>\u5728\u7ebf\u533b\u7597\u5e73\u53f0\u662f\u8fd1\u5e74\u6765\u8fc5\u901f\u53d1\u5c55\u8d77\u6765\u7684\u65b0\u578b\u533b\u7597\u670d\u52a1\u6a21\u5f0f\u3002\u5b83\u901a\u8fc7\u4e92\u8054\u7f51\u6280\u672f\u5b9e\u73b0\u4e86\u533b\u751f\u548c\u60a3\u8005\u4e4b\u95f4\u7684\u8fdc\u7a0b\u533b\u7597\u54a8\u8be2\u4e0e\u6cbb\u7597\uff0c\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u533b\u7597\u670d\u52a1\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Laravel\u6846\u67b6\u5f00\u53d1\u4e00\u4e2a\u57fa\u4e8e\u4e91\u8ba1\u7b97\u7684\u5728\u7ebf\u533b\u7597\u5e73\u53f0\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<ol>\n<li>\u51c6\u5907\u5de5\u4f5c\uff1a<br \/>\u5728\u5f00\u59cb\u5f00\u53d1\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86PHP\uff08\u7248\u672c&gt;= 7.2\uff09\u548c\u76f8\u5173\u7684\u5f00\u53d1\u5de5\u5177\uff0c\u4f8b\u5982composer\u7b49\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u4e00\u4e2aMySQL\u6570\u636e\u5e93\u4f5c\u4e3a\u540e\u7aef\u6570\u636e\u5b58\u50a8\u3002<\/li>\n<li>\u521b\u5efaLaravel\u9879\u76ee\uff1a<br \/>\u9996\u5148\uff0c\u6211\u4eec\u4f7f\u7528composer\u547d\u4ee4\u5b89\u88c5Laravel\u6846\u67b6\uff1a<\/li>\n<\/ol>\n<p>composer global require &#8220;\/installer&#8221;<\/p>\n<p>\u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Laravel\u9879\u76ee\uff1a<\/p>\n<p>laravel new medical-platform<\/p>\n<p>\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\uff1a<\/p>\n<p>cd medical-platform<\/p>\n<ol>\n<li>\u6570\u636e\u5e93\u914d\u7f6e\uff1a<br \/>\u5728.env\u6587\u4ef6\u4e2d\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\uff1a<\/li>\n<\/ol>\n<p>DB_CONNECTION=mysql<br \/>DB_HOST=127.0.0.1<br \/>DB_PORT=3306<br \/>DB_DATABASE=medical_platform<br \/>DB_USERNAME=root<br \/>DB_PASSWORD=<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<p>mysql -u root -p<br \/>CREATE DATABASE medical_platform;<\/p>\n<ol>\n<li>\u521b\u5efa\u6a21\u578b\u548c\u6570\u636e\u5e93\u8fc1\u79fb\uff1a<br \/>\u73b0\u5728\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e9b\u6a21\u578b\uff0c\u5e76\u751f\u6210\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u8fc1\u79fb\u6587\u4ef6\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p>php artisan make:model Category -m<br \/>php artisan make:model Doctor -m<br \/>php artisan make:model Patient -m<br \/>php artisan make:model Appointment -m<br \/>php artisan make:model Prescription -m<\/p>\n<p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u5728app\u76ee\u5f55\u4e0b\u751f\u6210\u5bf9\u5e94\u7684\u6a21\u578b\u6587\u4ef6\uff0c\u5e76\u5728database\/migrations\u76ee\u5f55\u4e0b\u751f\u6210\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u8fc1\u79fb\u6587\u4ef6\u3002<\/p>\n<p>\u5728\u751f\u6210\u7684\u8fc1\u79fb\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u5404\u4e2a\u8868\u7684\u5b57\u6bb5\u548c\u5173\u8054\u5173\u7cfb\u3002\u4f8b\u5982\uff0cDoctor\u6a21\u578b\u7684\u8fc1\u79fb\u6587\u4ef6\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>public function up()\n{\n    Schema::create('doctors', function (Blueprint $table) {\n        $table-&amp;gt;id();\n        $table-&amp;gt;string('name');\n        $table-&amp;gt;string('specialty');\n        $table-&amp;gt;timestamps();\n    });\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd0\u884c\u8fc1\u79fb\u547d\u4ee4\u5c06\u521b\u5efa\u6570\u636e\u5e93\u8868\uff1a<\/p>\n<p>php artisan migrate<\/p>\n<ol>\n<li>\u5b9a\u4e49\u8def\u7531\u548c\u63a7\u5236\u5668\uff1a<br \/>\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e9b\u8def\u7531\u548c\u63a7\u5236\u5668\u6765\u5904\u7406\u4e0d\u540c\u9875\u9762\u7684\u8bf7\u6c42\u3002\u6253\u5f00routes\/web.php\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>Route::get('\/', 'HomeController@index');\nRoute::get('\/doctors', 'DoctorController@index');\nRoute::get('\/doctors\/{id}', 'DoctorController@show');\nRoute::get('\/patients', 'PatientController@index');\nRoute::get('\/patients\/{id}', 'PatientController@show');\nRoute::get('\/appointments', 'AppointmentController@index');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u751f\u6210\u5bf9\u5e94\u7684\u63a7\u5236\u5668\u6587\u4ef6\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>php artisan make:controller HomeController<br \/>php artisan make:controller DoctorController<br \/>php artisan make:controller PatientController<br \/>php artisan make:controller AppointmentController<\/p>\n<p>\u5728\u751f\u6210\u7684\u63a7\u5236\u5668\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e0d\u540c\u8def\u7531\u5bf9\u5e94\u7684\u5904\u7406\u903b\u8f91\u3002\u4f8b\u5982\uff0cHomeController\u7684index\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>public function index()\n{\n    return view('home');\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u521b\u5efa\u89c6\u56fe\uff1a<br \/>\u5728resources\/views\u76ee\u5f55\u4e0b\u521b\u5efa\u5bf9\u5e94\u7684\u89c6\u56fe\u6587\u4ef6\uff0c\u4f8b\u5982home.blade.php\u3001doctors.blade.php\u3001patients.blade.php\u7b49\u3002<\/li>\n<\/ol>\n<p>\u5728\u89c6\u56fe\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Blade\u6a21\u677f\u5f15\u64ce\u6765\u6e32\u67d3\u52a8\u6001\u5185\u5bb9\u3002\u4f8b\u5982\uff0cdoctors.blade.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528@foreach\u6307\u4ee4\u6765\u904d\u5386\u533b\u751f\u5217\u8868\uff1a<\/p>\n<pre>@foreach ($doctors as $doctor)\n    &lt;div&gt;{{ $doctor-&amp;gt;name }}&lt;\/div&gt;\n@endforeach<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u521d\u59cb\u5316\u6570\u636e\uff1a<br \/>\u4e3a\u4e86\u65b9\u4fbf\u6d4b\u8bd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6570\u636e\u5e93\u4e2d\u521d\u59cb\u5316\u4e00\u4e9b\u6d4b\u8bd5\u6570\u636e\u3002\u5728database\/seeds\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2aDoctorsTableSeeder.php\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>public function run()\n{\n    DB::table('doctors')-&amp;gt;insert([\n        'name' =&amp;gt; 'John Doe',\n        'specialty' =&amp;gt; 'Cardiology',\n        'created_at' =&amp;gt; now(),\n        'updated_at' =&amp;gt; now(),\n    ]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u5728database\/seeds\/DatabaseSeeder.php\u6587\u4ef6\u4e2d\u8c03\u7528\u8be5Seeder\u7c7b\uff1a<\/p>\n<pre>public function run()\n{\n    $this-&amp;gt;call(DoctorsTableSeeder::class);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6267\u884c\u6570\u636e\u586b\u5145\uff1a<\/p>\n<p>php artisan db:seed<\/p>\n<ol>\n<li>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff1a<br \/>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8Laravel\u5185\u7f6e\u7684\u5f00\u53d1\u670d\u52a1\u5668\uff1a<\/li>\n<\/ol>\n<p>php artisan serve<\/p>\n<p>\u7136\u540e\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\uff0c\u8bbf\u95eehttp:\/\/localhost:8000\uff0c\u5373\u53ef\u67e5\u770b\u5728\u7ebf\u533b\u7597\u5e73\u53f0\u7684\u9996\u9875\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<br \/>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Laravel\u6846\u67b6\u5f00\u53d1\u4e00\u4e2a\u57fa\u4e8e\u4e91\u8ba1\u7b97\u7684\u5728\u7ebf\u533b\u7597\u5e73\u53f0\u3002\u6211\u4eec\u901a\u8fc7\u5b9a\u4e49\u6a21\u578b\u3001\u914d\u7f6e\u6570\u636e\u5e93\u3001\u521b\u5efa\u8def\u7531\u548c\u63a7\u5236\u5668\u3001\u7f16\u5199\u89c6\u56fe\u7b49\u6b65\u9aa4\uff0c\u6784\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u533b\u7597\u5e73\u53f0\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c\u8bfb\u8005\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63a2\u7d22\u548c\u5b66\u4e60Laravel\u6846\u67b6\u5728Web\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528Laravel\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u533b\u7597\u5e73\u53f0\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\u4f7f\u7528Laravel\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u533b\u7597\u5e73\u53f0 \u7b80\u4ecb\uff1a\u5728\u7ebf\u533b\u7597\u5e73\u53f0\u662f\u8fd1\u5e74\u6765\u8fc5\u901f\u53d1\u5c55\u8d77\u6765\u7684\u65b0\u578b\u533b\u7597\u670d\u52a1\u6a21\u5f0f\u3002\u5b83\u901a\u8fc7\u4e92\u8054\u7f51\u6280\u672f\u5b9e\u73b0\u4e86\u533b\u751f\u548c\u60a3\u8005\u4e4b\u95f4\u7684\u8fdc\u7a0b\u533b\u7597\u54a8\u8be2\u4e0e\u6cbb\u7597\uff0c\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u533b\u7597\u670d\u52a1\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Laravel\u6846\u67b6\u5f00\u53d1\u4e00\u4e2a\u57fa\u4e8e\u4e91\u8ba1\u7b97\u7684\u5728\u7ebf\u533b\u7597\u5e73\u53f0\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u51c6\u5907\u5de5\u4f5c\uff1a\u5728\u5f00\u59cb\u5f00\u53d1\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86PHP\uff08\u7248\u672c&gt;= 7.2\uff09\u548c\u76f8\u5173\u7684\u5f00\u53d1\u5de5\u5177\uff0c\u4f8b\u5982composer\u7b49\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u4e00\u4e2aMySQL\u6570\u636e\u5e93\u4f5c\u4e3a\u540e\u7aef\u6570\u636e\u5b58\u50a8\u3002 \u521b\u5efaLaravel\u9879\u76ee\uff1a\u9996\u5148\uff0c\u6211\u4eec\u4f7f\u7528composer\u547d\u4ee4\u5b89\u88c5Laravel\u6846\u67b6\uff1a composer global require &#8220;\/installer&#8221; \u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Laravel\u9879\u76ee\uff1a laravel new medical-platform \u8fdb\u5165\u9879\u76ee\u76ee\u5f55\uff1a cd medical-platform \u6570\u636e\u5e93\u914d\u7f6e\uff1a\u5728.env\u6587\u4ef6\u4e2d\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\uff1a DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=medical_platformDB_USERNAME=rootDB_PASSWORD= \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\uff1a mysql -u root -pCREATE DATABASE medical_platform; \u521b\u5efa\u6a21\u578b\u548c\u6570\u636e\u5e93\u8fc1\u79fb\uff1a\u73b0\u5728\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e9b\u6a21\u578b\uff0c\u5e76\u751f\u6210\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u8fc1\u79fb\u6587\u4ef6\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a php artisan make:model Category -mphp artisan make:model Doctor -mphp artisan make:model Patient -mphp artisan make:model Appointment -mphp artisan make:model Prescription -m \u8fd9\u4e9b\u547d\u4ee4\u5c06\u5728app\u76ee\u5f55\u4e0b\u751f\u6210\u5bf9\u5e94\u7684\u6a21\u578b\u6587\u4ef6\uff0c\u5e76\u5728database\/migrations\u76ee\u5f55\u4e0b\u751f\u6210\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u8fc1\u79fb\u6587\u4ef6\u3002 \u5728\u751f\u6210\u7684\u8fc1\u79fb\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u5404\u4e2a\u8868\u7684\u5b57\u6bb5\u548c\u5173\u8054\u5173\u7cfb\u3002\u4f8b\u5982\uff0cDoctor\u6a21\u578b\u7684\u8fc1\u79fb\u6587\u4ef6\u5982\u4e0b\u6240\u793a\uff1a public function up() { Schema::create(&#8216;doctors&#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-24819","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24819","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=24819"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24819\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}