{"id":22375,"date":"2024-11-21T10:46:44","date_gmt":"2024-11-21T02:46:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22375\/"},"modified":"2024-11-21T10:46:44","modified_gmt":"2024-11-21T02:46:44","slug":"laravel%e6%80%8e%e4%b9%88%e5%bf%ab%e9%80%9f%e6%90%ad%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22375\/","title":{"rendered":"laravel\u600e\u4e48\u5feb\u901f\u642d\u5efa"},"content":{"rendered":"<p>laravel\u662f\u4e00\u6b3e\u6d41\u884c\u7684php\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u5f00\u53d1\u5de5\u5177\u548c\u4f18\u79c0\u7684\u6027\u80fd\u8868\u73b0\uff0c\u6210\u4e3a\u4e86\u8bb8\u591aweb\u5f00\u53d1\u8005\u7684\u9996\u9009\u3002\u5bf9\u4e8e\u60f3\u8981\u8fc5\u901f\u5b66\u4e60\u548c\u642d\u5efalaravel\u9879\u76ee\u7684\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u63a5\u4e0b\u6765\u7684\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4e9b\u57fa\u672c\u7684\u6307\u5bfc\u3002<\/p>\n<p>\u73af\u5883\u642d\u5efa<\/p>\n<p>\u5728\u5f00\u59cb\u4f7f\u7528Laravel\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u7535\u8111\u5df2\u7ecf\u5b89\u88c5\u4e86PHP\u548cComposer\u8fd9\u4e24\u4e2a\u5de5\u5177\u3002PHP\u662fLaravel\u4f9d\u8d56\u7684\u6838\u5fc3\u8bed\u8a00\uff0c\u800cComposer\u5219\u662fPHP\u7684\u4f9d\u8d56\u7ba1\u7406\u5668\u3002\u5728\u5b89\u88c5Composer\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Laravel\uff1a<\/p>\n<pre>composer global require laravel\/installer<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<pre>laravel --version<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u521b\u5efa\u9879\u76ee<\/p>\n<p>\u5728\u5b89\u88c5\u5b8c\u6210Laravel\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Laravel\u9879\u76ee\uff1a<\/p>\n<pre>laravel new my-project<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u91ccmy-project\u5c31\u662f\u4f60\u60f3\u8981\u521b\u5efa\u7684\u9879\u76ee\u7684\u540d\u79f0\u3002Laravel\u5c06\u4f1a\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2aLaravel\u9879\u76ee\uff1a<\/p>\n<pre>composer create-project --prefer-dist laravel\/laravel my-project<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u901a\u8fc7Composer\u4ecePackagist\u4e0a\u5b89\u88c5Laravel\uff0c\u7136\u540e\u5728my-project\u76ee\u5f55\u91cc\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\u3002<\/p>\n<p>\u542f\u52a8\u9879\u76ee<\/p>\n<p>Laravel\u9879\u76ee\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8\u9879\u76ee\uff1a<\/p>\n<pre>php artisan serve<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f1a\u5728\u672c\u5730\u542f\u52a8\u4e00\u4e2aWeb\u670d\u52a1\u5668\u5e76\u76d1\u542c8000\u7aef\u53e3\u3002\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165http:\/\/localhost:8000\u5c31\u53ef\u4ee5\u8bbf\u95ee\u7ad9\u70b9\u3002<\/p>\n<p>\u914d\u7f6e\u6570\u636e\u5e93<\/p>\n<p>Laravel\u9ed8\u8ba4\u4f7f\u7528SQLite\u6570\u636e\u5e93\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\u5e93\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002\u5728Laravel\u4e2d\uff0c\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u4f4d\u4e8econfig\/database.php\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u91cc\u8fdb\u884c\u6570\u636e\u5e93\u914d\u7f6e\u3002<\/p>\n<p>\u5728config\/database.php\u4e2d\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u8fd9\u6837\u7684\u914d\u7f6e\uff0c\u8fd9\u662f\u9ed8\u8ba4\u7684SQLite\u914d\u7f6e\uff1a<\/p>\n<pre>'sqlite' =&gt; [\n    'driver' =&gt; 'sqlite',\n    'url' =&gt; env('DATABASE_URL'),\n    'database' =&gt; env('DB_DATABASE', database_path('database.sqlite')),\n    'prefix' =&gt; '',\n    'foreign_key_constraints' =&gt; env('DB_FOREIGN_KEYS', true),\n],<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u914d\u7f6e\u66ff\u6362\u6210\u5176\u4ed6\u7c7b\u578b\u6570\u636e\u5e93\u7684\u914d\u7f6e\uff0c\u6bd4\u5982MySQL\u3002\u6bd4\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2aMySQL\u914d\u7f6e\uff1a<\/p>\n<pre>'mysql' =&gt; [\n    'driver' =&gt; 'mysql',\n    'url' =&gt; env('DATABASE_URL'),\n    'host' =&gt; env('DB_HOST', '127.0.0.1'),\n    'port' =&gt; env('DB_PORT', '3306'),\n    'database' =&gt; env('DB_DATABASE', 'laravel'),\n    'username' =&gt; env('DB_USERNAME', 'root'),\n    'password' =&gt; env('DB_PASSWORD', ''),\n    'unix_socket' =&gt; env('DB_SOCKET', ''),\n    'charset' =&gt; 'utf8mb4',\n    'collation' =&gt; 'utf8mb4_unicode_ci',\n    'prefix' =&gt; '',\n    'prefix_indexes' =&gt; true,\n    'strict' =&gt; true,\n    'engine' =&gt; null,\n    'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([\n        PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),\n    ]) : [],\n],<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u914d\u7f6e\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u4fee\u6539\u7684\u5b57\u6bb5\u5305\u62echost\u3001port\u3001database\u3001username\u548cpassword\uff0c\u8fd9\u4e9b\u5b57\u6bb5\u9700\u8981\u8bbe\u7f6e\u6210\u4f60\u81ea\u5df1\u7684\u6570\u636e\u5e93\u914d\u7f6e\u3002<\/p>\n<p>\u521b\u5efa\u63a7\u5236\u5668\u548c\u89c6\u56fe<\/p>\n<p>\u5728Laravel\u4e2d\u521b\u5efa\u4e00\u4e2a\u63a7\u5236\u5668\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a<\/p>\n<pre>php artisan make:controller HomeController<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u91cc\u521b\u5efa\u4e86\u4e00\u4e2a\u53eb\u505aHomeController\u7684\u63a7\u5236\u5668\u3002\u63a7\u5236\u5668\u7684\u4f5c\u7528\u662f\u63a5\u53d7\u7528\u6237\u7684\u8bf7\u6c42\u5e76\u8fd4\u56de\u54cd\u5e94\u3002<\/p>\n<p>\u5f53\u63a7\u5236\u5668\u4e2d\u9700\u8981\u5207\u6362\u89c6\u56fe\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u89c6\u56fe\u6587\u4ef6\uff1a<\/p>\n<pre>php artisan make:view home<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u91cc\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u5b57\u4e3ahome\u7684\u89c6\u56fe\uff0c\u53ef\u4ee5\u5728HomeController\u4e2d\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u6765\u6e32\u67d3home\u89c6\u56fe\uff1a<\/p>\n<pre>return view('home');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728web.php\u6587\u4ef6\u4e2d\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u7ed1\u5b9aURL\u548c\u63a7\u5236\u5668\uff1a<\/p>\n<pre>Route::get('\/', 'HomeController@index')-&gt;name('home');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c06\u9996\u9875(\/)\u548cHomeController\u4e2d\u7684index\u65b9\u6cd5\u7ed1\u5b9a\u5728\u4e00\u8d77\uff0c\u5e76\u4f7f\u7528home\u4f5c\u4e3a\u540d\u79f0\u3002\u63a5\u4e0b\u6765\uff0c\u5728\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0index\u65b9\u6cd5\uff1a<\/p>\n<pre>public function index()\n{\n    return view('home');\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u91cc\u662f\u4e00\u4e2a\u7b80\u5355\u7684HomeController\u4ee3\u7801\uff0c\u5b83\u8fd4\u56de\u4e86\u4e00\u4e2ahome\u89c6\u56fe\uff1a<\/p>\n<pre>&lt;?php\n\nnamespace AppHttpControllers;\n\nuse IlluminateHttpRequest;\n\nclass HomeController extends Controller\n{\n    public function index()\n    {\n        return view('home');\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7ed3\u8bba<\/p>\n<p>\u672c\u6587\u63d0\u4f9b\u4e86\u5bf9\u4e8e\u5feb\u901f\u642d\u5efalaravel\u9879\u76ee\u7684\u6559\u5b66\uff0c\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u5230\u90e8\u5206\u60f3\u5b66\u4e60laravel\u6846\u67b6\uff0c\u5e76\u4e14\u642d\u5efa\u5c5e\u4e8e\u81ea\u5df1laravel\u9879\u76ee\u7684\u5f00\u53d1\u8005\u3002\u5f53\u7136\uff0c\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u8fd8\u9700\u8981\u66f4\u6df1\u5165\u7684\u5b66\u4e60\u548c\u4e86\u89e3\uff0c\u624d\u80fd\u66f4\u597d\u5730\u4f7f\u7528Laravel\u8fdb\u884c\u5f00\u53d1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel\u600e\u4e48\u5feb\u901f\u642d\u5efa\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\u4e00\u6b3e\u6d41\u884c\u7684php\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u5f00\u53d1\u5de5\u5177\u548c\u4f18\u79c0\u7684\u6027\u80fd\u8868\u73b0\uff0c\u6210\u4e3a\u4e86\u8bb8\u591aweb\u5f00\u53d1\u8005\u7684\u9996\u9009\u3002\u5bf9\u4e8e\u60f3\u8981\u8fc5\u901f\u5b66\u4e60\u548c\u642d\u5efalaravel\u9879\u76ee\u7684\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u63a5\u4e0b\u6765\u7684\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4e9b\u57fa\u672c\u7684\u6307\u5bfc\u3002 \u73af\u5883\u642d\u5efa \u5728\u5f00\u59cb\u4f7f\u7528Laravel\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u7535\u8111\u5df2\u7ecf\u5b89\u88c5\u4e86PHP\u548cComposer\u8fd9\u4e24\u4e2a\u5de5\u5177\u3002PHP\u662fLaravel\u4f9d\u8d56\u7684\u6838\u5fc3\u8bed\u8a00\uff0c\u800cComposer\u5219\u662fPHP\u7684\u4f9d\u8d56\u7ba1\u7406\u5668\u3002\u5728\u5b89\u88c5Composer\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Laravel\uff1a composer global require laravel\/installer \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a laravel &#8211;version \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u9879\u76ee \u5728\u5b89\u88c5\u5b8c\u6210Laravel\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Laravel\u9879\u76ee\uff1a laravel new my-project \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91ccmy-project\u5c31\u662f\u4f60\u60f3\u8981\u521b\u5efa\u7684\u9879\u76ee\u7684\u540d\u79f0\u3002Laravel\u5c06\u4f1a\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002 \u4e5f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2aLaravel\u9879\u76ee\uff1a composer create-project &#8211;prefer-dist laravel\/laravel my-project \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u79cd\u65b9\u5f0f\u4f1a\u901a\u8fc7Composer\u4ecePackagist\u4e0a\u5b89\u88c5Laravel\uff0c\u7136\u540e\u5728my-project\u76ee\u5f55\u91cc\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\u3002 \u542f\u52a8\u9879\u76ee Laravel\u9879\u76ee\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8\u9879\u76ee\uff1a php artisan serve \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e2a\u547d\u4ee4\u5c06\u4f1a\u5728\u672c\u5730\u542f\u52a8\u4e00\u4e2aWeb\u670d\u52a1\u5668\u5e76\u76d1\u542c8000\u7aef\u53e3\u3002\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165http:\/\/localhost:8000\u5c31\u53ef\u4ee5\u8bbf\u95ee\u7ad9\u70b9\u3002 \u914d\u7f6e\u6570\u636e\u5e93 Laravel\u9ed8\u8ba4\u4f7f\u7528SQLite\u6570\u636e\u5e93\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\u5e93\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002\u5728Laravel\u4e2d\uff0c\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u4f4d\u4e8econfig\/database.php\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u91cc\u8fdb\u884c\u6570\u636e\u5e93\u914d\u7f6e\u3002 \u5728config\/database.php\u4e2d\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u8fd9\u6837\u7684\u914d\u7f6e\uff0c\u8fd9\u662f\u9ed8\u8ba4\u7684SQLite\u914d\u7f6e\uff1a &#8216;sqlite&#8217; =&gt; [ &#8216;driver&#8217; =&gt; &#8216;sqlite&#8217;, &#8216;url&#8217; =&gt; env(&#8216;DATABASE_URL&#8217;), &#8216;database&#8217; =&gt; env(&#8216;DB_DATABASE&#8217;, database_path(&#8216;database.sqlite&#8217;)), &#8216;prefix&#8217; =&gt; &#8221;, &#8216;foreign_key_constraints&#8217; =&gt; [&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-22375","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22375","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=22375"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22375\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}