{"id":22482,"date":"2024-11-21T11:28:55","date_gmt":"2024-11-21T03:28:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22482\/"},"modified":"2024-11-21T11:28:55","modified_gmt":"2024-11-21T03:28:55","slug":"laravel-%e5%90%af%e5%8a%a8%e8%bf%87%e7%a8%8b%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22482\/","title":{"rendered":"laravel \u542f\u52a8\u8fc7\u7a0b\u662f\u4ec0\u4e48"},"content":{"rendered":"<p>laravel\u662f\u4e00\u6b3e\u6d41\u884c\u7684php\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u7684\u542f\u52a8\u8fc7\u7a0b\u4e0e\u5176\u4ed6\u6846\u67b6\u7c7b\u4f3c\uff0c\u90fd\u9700\u8981\u7ecf\u5386\u4e00\u5b9a\u7684\u51c6\u5907\u5de5\u4f5c\u3002\u672c\u6587\u5c06\u9488\u5bf9laravel\u7684\u542f\u52a8\u8fc7\u7a0b\u8fdb\u884c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p>\u4e00\u3001\u5165\u53e3\u6587\u4ef6index.php<\/p>\n<p>Laravel\u7684\u5165\u53e3\u6587\u4ef6\u662findex.php\uff0c\u6240\u6709\u8bf7\u6c42\u90fd\u5c06\u901a\u8fc7\u8fd9\u4e2a\u6587\u4ef6\u8fdb\u5165\u6846\u67b6\u3002\u5728index.php\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0b\u4ee3\u7801\u6bb5\uff1a<\/p>\n<pre>\/*\n|--------------------------------------------------------------------------\n| Turn On The Lights\n|--------------------------------------------------------------------------\n|\n| We need to illuminate PHP development, so let us turn on the lights.\n| This bootstraps the framework and gets it ready for use, then it\n| will load up this application so that we can run it and send\n| the responses back to the browser and delight our users.\n|\n*\/\n\n$app = require_once __DIR__.'\/..\/bootstrap\/app.php';<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6bb5\u6ce8\u91ca\u89e3\u91ca\u4e86\u4ee3\u7801\u7684\u4f5c\u7528\uff0c\u4e5f\u53ef\u4ee5\u770b\u5230require_once\u5f15\u5165\u4e86bootstrap\/app.php\u8fd9\u4e2a\u6587\u4ef6\uff0c\u4e5f\u5c31\u662fLaravel\u7684\u542f\u52a8\u6587\u4ef6\u3002<\/p>\n<p>\u4e8c\u3001\u542f\u52a8\u6587\u4ef6bootstrap\/app.php<\/p>\n<p>\u5728app.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3b\u8981\u770b\u5230\u4e09\u4e2a\u5173\u952e\u7c7b\u7684\u5b9e\u4f8b\u5316\uff1a$app\u3001$kernel\u3001$router\u3002\u4e0b\u9762\u6211\u4eec\u6765\u9010\u4e00\u4ecb\u7ecd\u3002<\/p>\n<ol>\n<li>$app<\/li>\n<\/ol>\n<p>$app\u662fIlluminateFoundationApplication\u7c7b\u7684\u5b9e\u4f8b\uff0c\u662f\u6574\u4e2a\u6846\u67b6\u7684\u6838\u5fc3\uff0c\u5b83\u7ba1\u7406\u4e86 Laravel \u5e94\u7528\u7a0b\u5e8f\u7684\u5bb9\u5668\u5e76\u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u6709\u529b\u7684\u529f\u80fd\uff0c\u5982\u8def\u7531\u3001\u8bf7\u6c42\u5904\u7406\u3001\u4e8b\u4ef6\u3001cookie\u3001session\u3001\u5f02\u5e38\u5904\u7406\u7b49\u7b49\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5148\u770b\u4e00\u4e0b$app\u5982\u4f55\u521d\u59cb\u5316\u3002<\/p>\n<p>\u5728$app\u7684\u6784\u9020\u51fd\u6570\u4e2d\uff0c\u5b83\u9996\u5148\u7ee7\u627f\u4e86IlluminateContainerContainer\u7c7b\uff0c\u751f\u6210\u4e86\u4e00\u4e2a\u5bb9\u5668\u5b9e\u4f8b\u3002\u5728\u8fd9\u4e2a\u5bb9\u5668\u5b9e\u4f8b\u4e2d\u6211\u4eec\u53ef\u4ee5\u7ed1\u5b9a\u548c\u6ce8\u5165\u6211\u4eec\u9700\u8981\u7684\u670d\u52a1\u3002<\/p>\n<p>\u63a5\u7740\uff0c\u5b83\u4f1a\u6ce8\u518cLaravel\u7684\u6240\u6709\u6838\u5fc3\u5bb9\u5668\u670d\u52a1\uff0c\u5982\u8def\u7531\u3001\u65e5\u5fd7\u3001\u89c6\u56fe\u7b49\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5b83\u4f1a\u52a0\u8f7dLaravel\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u4e9b\u914d\u7f6e\u6587\u4ef6\u5b58\u653e\u5728config\u76ee\u5f55\u4e0b\uff0c\u5e76\u5c06\u5176\u653e\u5165$app\u5b9e\u4f8b\u7684\u5c5e\u6027\u4e2d\u3002<\/p>\n<ol>\n<li>$kernel<\/li>\n<\/ol>\n<p>$kernel\u662fIlluminateContractsHttpKernel\u63a5\u53e3\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u5b83\u662fLaravel\u7684HTTP\u5185\u6838\uff0c\u8d1f\u8d23\u5904\u7406\u6240\u6709\u7684HTTP\u8bf7\u6c42\uff0c\u662f\u8fde\u63a5\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u6865\u6881\u3002$kernel\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u8c03\u7528\u8bf7\u6c42\u7684\u4e2d\u95f4\u4ef6\uff0c\u5e76\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u8def\u7531\u5668\uff0c\u6700\u540e\u5c06\u54cd\u5e94\u4f20\u9012\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u5728$app\u5b9e\u4f8b\u5316\u540e\uff0c\u5b83\u4f1a\u8c03\u7528$app-&gt;make()\u65b9\u6cd5\u7136\u540e\u901a\u8fc7\u5bb9\u5668\u89e3\u6790\u83b7\u53d6$kernel\u7684\u5b9e\u4f8b\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c$app\u7684\u5bb9\u5668\u4f1a\u89e3\u6790$config[&#8216;app&#8217;][&#8216;middleware&#8217;]\u914d\u7f6e\u5e76\u6ce8\u518c\u4e2d\u95f4\u4ef6\uff0c\u7136\u540e\u5c06\u4e2d\u95f4\u4ef6\u5b58\u50a8\u5230$kernel\u7684\u5b9e\u4f8b\u4e2d\u3002<\/p>\n<ol>\n<li>$router<\/li>\n<\/ol>\n<p>$router\u662fIlluminateRoutingRouter\u7c7b\u7684\u5b9e\u4f8b\uff0c\u5b83\u662fLaravel\u7684\u8def\u7531\u5668\uff0c\u5904\u7406\u6240\u6709\u7684\u8def\u7531\u89e3\u6790\u548c\u5206\u53d1\u3002$router\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u5c06\u8bf7\u6c42\u548c\u76f8\u5e94\u7684\u64cd\u4f5c\u8fdb\u884c\u5339\u914d\uff0c\u4e3a\u8bf7\u6c42\u5c06\u88ab\u5904\u7406\u7684\u8def\u7531\u5b58\u50a8\u5728\u8bf7\u6c42\u5b9e\u4f8b\u7684\u5c5e\u6027\u4e2d\u3002<\/p>\n<p>\u5728$app\u5b9e\u4f8b\u5316\u540e\uff0c\u5b83\u4f1a\u4f7f\u7528\u76f8\u5e94\u7684\u914d\u7f6e\u751f\u6210\u8def\u7531\u5668\u5b9e\u4f8b\uff0c\u5e76\u901a\u8fc7$app\u5b9e\u4f8b\u7684instance\u65b9\u6cd5\u6ce8\u518c\u5230Laravel\u7684\u5bb9\u5668\u4e2d\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u63d0\u5230\u7684\u662f\uff0c$app\u4f1a\u5c06\u8bf7\u6c42\u5b9e\u4f8b\u53ca\u5176\u5b83\u76f8\u5173\u5b9e\u4f8b\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\uff0c\u4ee5\u4f9b\u4e2d\u95f4\u4ef6\u3001\u8def\u7531\u548c\u63a7\u5236\u5668\u4f7f\u7528\u3002\u5bb9\u5668\u7ed1\u5b9a\u5b8c\u6210\u540e\uff0cLaravel\u5c31\u5b8c\u6210\u4e86\u51c6\u5907\u5de5\u4f5c\u3002<\/p>\n<p>\u4e09\u3001\u8c03\u5ea6\u8bf7\u6c42<\/p>\n<p>\u5728Laravel\u4e2d\uff0c\u8bf7\u6c42\u7684\u8c03\u5ea6\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>1.\u4ece\u5ba2\u6237\u7aef\u53d1\u8d77HTTP\u8bf7\u6c42\u3002<\/p>\n<p>2.\u8bf7\u6c42\u9996\u5148\u7ecf\u8fc7Laravel\u7684public\/index.php\u6587\u4ef6\uff0c\u5e76\u88ab\u8f6c\u53d1\u5230bootstrap\/app.php\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>3.\u5728bootstrap\/app.php\u6587\u4ef6\u4e2d\uff0cLaravel\u751f\u6210$app\u3001$kernel\u548c$router\u7684\u5b9e\u4f8b\uff0c\u5e76\u5c06\u8bf7\u6c42\u5b9e\u4f8b\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\u3002\u7136\u540e$app\u4f1a\u8c03\u7528$kernel\u7684handle\u65b9\u6cd5\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>4.\u5728$kernel\u7684handle\u65b9\u6cd5\u4e2d\uff0cLaravel\u901a\u8fc7\u5bb9\u5668\u89e3\u6790\u5e76\u4f9d\u6b21\u8c03\u7528\u6ce8\u518c\u7684\u4e2d\u95f4\u4ef6\uff0c\u7136\u540e\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u8def\u7531\u5668\u3002<\/p>\n<p>5.\u5728\u8def\u7531\u5668\u4e2d\uff0cLaravel\u4ece\u8bf7\u6c42\u4e2d\u63d0\u53d6URI\uff0c\u7136\u540e\u5c06\u5176\u4e0e\u8def\u7531\u5668\u5b9e\u4f8b\u4e2d\u5b9a\u4e49\u7684\u6240\u6709\u8def\u7531\u8fdb\u884c\u5339\u914d\u3002\u5982\u679c\u627e\u5230\u5339\u914d\u7684\u8def\u7531\uff0cLaravel\u5c31\u5c06\u63a7\u5236\u6743\u4f20\u9012\u7ed9\u76f8\u5e94\u7684\u63a7\u5236\u5668\u3002<\/p>\n<p>6.\u63a7\u5236\u5668\u662f\u8bf7\u6c42\u7684\u4e3b\u8981\u5904\u7406\u7a0b\u5e8f\uff0c\u5b83\u4f1a\u8c03\u7528\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u5904\u7406\u8bf7\u6c42\uff0c\u5e76\u6700\u7ec8\u5c06\u7ed3\u679c\u4f5c\u4e3a\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>7.\u5982\u679c\u8def\u7531\u5668\u6ca1\u6709\u627e\u5230\u5339\u914d\u7684\u8def\u7531\uff0c\u5b83\u4f1a\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u3002<\/p>\n<p>8.\u5728\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0cLaravel\u4f1a\u6839\u636e\u9519\u8bef\u7684\u7c7b\u578b\u548c\u914d\u7f6e\uff0c\u751f\u6210\u76f8\u5e94\u7684\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e00\u4e2aLaravel\u8bf7\u6c42\u7684\u5b8c\u6574\u6d41\u7a0b\u3002\u901a\u8fc7\u6df1\u5165\u4e86\u89e3Laravel\u7684\u542f\u52a8\u8fc7\u7a0b\u548c\u8bf7\u6c42\u8c03\u5ea6\u6d41\u7a0b\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u7684\u7406\u89e3\u5b83\u7684\u5185\u90e8\u67b6\u6784\u548c\u5de5\u4f5c\u539f\u7406\uff0c\u4ece\u800c\u66f4\u597d\u5730\u8fd0\u7528\u5b83\u5904\u7406\u6211\u4eec\u7684\u4e1a\u52a1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel \u542f\u52a8\u8fc7\u7a0b\u662f\u4ec0\u4e48\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\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u7684\u542f\u52a8\u8fc7\u7a0b\u4e0e\u5176\u4ed6\u6846\u67b6\u7c7b\u4f3c\uff0c\u90fd\u9700\u8981\u7ecf\u5386\u4e00\u5b9a\u7684\u51c6\u5907\u5de5\u4f5c\u3002\u672c\u6587\u5c06\u9488\u5bf9laravel\u7684\u542f\u52a8\u8fc7\u7a0b\u8fdb\u884c\u8be6\u7ec6\u4ecb\u7ecd\u3002 \u4e00\u3001\u5165\u53e3\u6587\u4ef6index.php Laravel\u7684\u5165\u53e3\u6587\u4ef6\u662findex.php\uff0c\u6240\u6709\u8bf7\u6c42\u90fd\u5c06\u901a\u8fc7\u8fd9\u4e2a\u6587\u4ef6\u8fdb\u5165\u6846\u67b6\u3002\u5728index.php\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0b\u4ee3\u7801\u6bb5\uff1a \/* |&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; | Turn On The Lights |&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the [&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-22482","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22482","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=22482"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22482\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}