{"id":206,"date":"2018-11-29T00:11:34","date_gmt":"2018-11-28T16:11:34","guid":{"rendered":"https:\/\/103.249.111.182\/?p=206"},"modified":"2018-11-29T00:11:34","modified_gmt":"2018-11-28T16:11:34","slug":"%e7%ac%94%e8%ae%b0laravel%e8%b7%af%e7%94%b1%e4%bd%bf%e7%94%a8%e7%ac%94%e8%ae%b0v1-0","status":"publish","type":"post","link":"https:\/\/7gugu.com\/index.php\/2018\/11\/29\/%e7%ac%94%e8%ae%b0laravel%e8%b7%af%e7%94%b1%e4%bd%bf%e7%94%a8%e7%ac%94%e8%ae%b0v1-0\/","title":{"rendered":"[\u7b14\u8bb0][laravel]\u8def\u7531\u4f7f\u7528\u7b14\u8bb0v1.0"},"content":{"rendered":"<p><strong>Laravel\u8def\u7531\u7b80\u4ecb:<\/strong><br \/>\n\u8def\u7531\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8bbf\u95ee\u7684\u8def\u5f84,\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2aaction<br \/>\n\u6bd4\u5982:<br \/>\n\u8f93\u51fa\u89c6\u56fe<\/p>\n<pre>\nRoute::any('\/',function(){\n  return view('welcome');\/\/\u8f93\u51fa\u6a21\u677fwelcome\n});\nRoute::any('\/',function(){\n  return 'Hello World';\/\/\u5355\u7eaf\u7684\u8f93\u51fa\u6587\u5b57\n});\n<\/pre>\n<p>\u4e00\u822c\u8def\u7531\u5668\u4e0d\u4f1a\u76f4\u63a5\u8f93\u51fa\u89c6\u56fe,\u53ea\u4f1a\u7528\u6765\u7ed1\u5b9a\u63a7\u5236\u5668,\u5e76\u4e14\u8fdb\u884c\u4f20\u53c2\u64cd\u4f5c<\/p>\n<hr \/>\n<h2>\u8def\u7531\u4f20\u53c2<\/h2>\n<p>\u6bd4\u5982:<br \/>\nweb.php<\/p>\n<pre>Route::any('\/center\/{id}','CenterController@id');<\/pre>\n<p>(\u6ce8\u91ca:\u628aid\u8fd9\u4e2a\u53c2\u6570\u4f20\u5165<code>CenterController<\/code>\u8fd9\u4e2a\u63a7\u5236\u5668\u7684<code>id<\/code>\u8fd9\u4e2a\u65b9\u6cd5)<br \/>\napp\/Http\/CenterController.php<\/p>\n<pre>\nnamespace App\\Http\\Controllers;\n\nclass CenterController extends Controller{\n  public function id($id){\nreturn 'Member-ID-'.$id;\n}\n}\n<\/pre>\n<p>(\u6ce8\u91ca:\u63a5\u6536\u6765\u81ea\u8def\u7531\u4f20\u5165\u53d8\u91cfid)<\/p>\n<pre>\nRoute::any('\/center\/{name?}','CenterController@id');<\/pre>\n<p>(\u6ce8\u91ca:\u6b64\u5904\u53d8\u91cfname\u540e\u9762\u7684&#8221;?&#8221;\u7684\u4f5c\u7528\u662f\u8bf4\u660e\u8be5\u53d8\u91cf\u5177\u6709\u9ed8\u8ba4\u503c,\u5373\u53ef\u4ee5\u5728\u63a7\u5236\u5668\u4e2d\u5bf9\u5e94\u7684\u65b9\u6cd5\u4e2d\u4f20\u53c2\u65f6\u8bbe\u5b9a\u4e00\u4e2a\u9ed8\u8ba4\u53c2\u6570,\u5982\u679c\u4e0d\u4f7f\u7528\u8be5\u6807\u8bc6\u7684\u8bdd\u4f1a\u5bfc\u81f4\u8bbf\u95ee\u65f6\u51fa\u73b0\u62a5\u9519\/404\u9875\u9762\u7684\u51fa\u73b0)<\/p>\n<hr \/>\n<h2>\u8def\u7531\u53c2\u6570\u8fc7\u6ee4\u5668<\/h2>\n<p>\u6bd4\u5982:<br \/>\n\u8fc7\u6ee4\u5355\u4e2a\u53c2\u6570<\/p>\n<pre>Route::any(\"\/center\/{id}\",'CenterController@id')-&gt;where('id','[0-9]+');<\/pre>\n<p>\u8fc7\u6ee4\u591a\u4e2a\u53c2\u6570<\/p>\n<pre>Route::any(\"\/center\/{id}\/{name}\",'CenterController@id')-&gt;where(['id'=&gt;'[0-9]+','name'=&gt;'[A-Za-z]+']);<\/pre>\n<p>(\u6ce8\u91ca:where\u628a\u8def\u7531\u6307\u5411where\u51fd\u6570\u5373\u53ef\u542f\u7528\u8fc7\u6ee4\u5668,\u8fc7\u6ee4\u5668\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8981\u8fc7\u6ee4\u7684\u53d8\u91cf\u540d,\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u8fc7\u6ee4\u7684\u6b63\u5219\u8868\u8fbe\u5f0f,\u5982\u679c\u4e0d\u9075\u5faa\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bdd,\u4f1a\u5148\u5339\u914d\u5176\u4ed6\u8def\u7531\u89c4\u5219,\u82e5\u65e0\u7b26\u5408\u7684\u89c4\u5219,\u5219\u4f1a\u629b\u51fa404\/\u9519\u8bef)<\/p>\n<hr \/>\n<h2>Laravel\u8def\u7531\u7c7b\u578b:<\/h2>\n<ol>\n<li>Get\u8def\u7531<\/li>\n<li>Post\u8def\u7531<\/li>\n<li>Any\u8def\u7531<\/li>\n<li>Match\u8def\u7531<\/li>\n<\/ol>\n<hr \/>\n<p>\u4e0b\u9762\u5c06\u5f00\u59cb\u8be6\u89e3\u6bcf\u4e00\u4e2a\u8def\u7531\u7684\u7528\u6cd5(\u4e2a\u4eba\u603b\u7ed3\u7684\u7b14\u8bb0)<\/p>\n<h3>Get\u8def\u7531<\/h3>\n<pre>\nRoute::get('\/','ControllerName@MethodName');\n<\/pre>\n<p>\u987e\u540d\u601d\u4e49\u901a\u8fc7\u7ed9\u670d\u52a1\u5668\u53d1\u8d77get\u8bf7\u6c42\u65f6,\u53ef\u4ee5\u89e6\u53d1\u8be5\u8def\u7531\u64cd\u4f5c<\/p>\n<h3>Post\u8def\u7531<\/h3>\n<pre>\nRoute::post('\/','ControllerName@MethodName');\n<\/pre>\n<p>\u53ea\u6709\u5f53\u53d1\u8d77post\u8bf7\u6c42\u65f6,\u624d\u4f1a\u89e6\u53d1\u8be5\u8def\u7531\u7ed1\u5b9a\u7684\u63a7\u5236\u5668<br \/>\n\u82e5\u76f4\u63a5\u8bbf\u95ee\u8be5\u8def\u7531,\u5c06\u4f1a\u629b\u51fa\u9519\u8bef<\/p>\n<p>Any\u8def\u7531(\u591a\u8bf7\u6c42\u8def\u7531)<\/p>\n<pre>\nRoute::any('\/','ControllerName@MethodName');\n<\/pre>\n<p>any\u8def\u7531\u5176\u5b9e\u5c31\u662fpost\u4e0eget\u8def\u7531\u7684\u7ed3\u5408\u4f53,\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528post\u8bf7\u6c42\/get\u8bf7\u6c42\u6765\u8bbf\u95ee\u8be5\u8def\u7531<\/p>\n<p>Match\u8def\u7531(\u591a\u8bf7\u6c42\u8def\u7531)<\/p>\n<pre>\nRoute::match(['get','post'],'\/','ControllerName@MethodName');\n<\/pre>\n<p>\u5728match\u8def\u7531\u4e2d,\u8be5\u8def\u7531\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f7f\u7528\u6765\u914d\u7f6e\u8be5\u8def\u7531\u53ef\u4ee5\u63a5\u53d7\u4ec0\u4e48\u6837\u7684\u8bf7\u6c42(\u8be6\u7ec6\u53ef\u4ee5\u63a5\u53d7\u4ec0\u4e48\u6837\u5b50\u7684\u53c2\u6570\u5f85\u4ee5\u540e\u518d\u66f4\u65b0)<\/p>\n<hr \/>\n<h2>\u8def\u7531\u7fa4\u7ec4:<\/h2>\n<pre>\nRoute::group(['prefix'=&amp;gt;'member'],function(){\n    Route::any('user\/member-center',['as'=&gt;'center',function(){\n        return route('center');\n    }]);\n    Route::get('\/basic1',function(){\n        return 'Hello world';\n    });\/\/GET\u8def\u7531\n});\n<\/pre>\n<p>\u8def\u7531\u7fa4\u7ec4\u7684\u4f5c\u7528:<br \/>\n\u53ef\u4ee5\u628a\u8def\u7531\u5206\u95e8\u522b\u7c7b\u7684\u653e\u7f6e\u5230\u4e00\u4e2a\u7fa4\u7ec4\u4e2d,\u4f7f\u7528\u8def\u7531\u524d\u7f00\u8fdb\u884c\u8bbf\u95ee<br \/>\n\u5982localhost\/member\/basic1\u8bbf\u95ee\u7684\u5c31\u662f\u4f4d\u4e8emember\u7fa4\u7ec4\u4e0b\u7684basic1\u8def\u7531<\/p>\n<hr \/>\n<h2>\u8def\u7531\u522b\u540d:<\/h2>\n<pre>\nRoute::get('user\/member-center',['as'=&gt;'center',function(){\n    return route('center');\/\/\u83b7\u53d6center\u8def\u7531\u7684\u5b8c\u6574\u5730\u5740\n}]);\n<\/pre>\n<p>\u8def\u7531\u522b\u540d\u7684\u4f5c\u7528\u5c31\u662f\u4f7f\u7528route\u65f6\u4f7f\u7528\u5df2\u9884\u5b9a\u597d\u540d\u5b57\u5bf9\u5e94\u7684\u8def\u7531<br \/>\n\u6bd4\u5982:route(&#8216;center&#8217;)\u5bf9\u5e94\u7684\u5c31\u662flocalhost\/user\/member-center<br \/>\n\u5982\u679c\u6b64\u65f6\u9700\u8981\u4fee\u6539url\u4ec5\u9700\u8981\u5728\u8def\u7531\u8fd9\u4fee\u6539,\u5373\u53ef\u505a\u5230\u5168\u9879\u76ee\u4fee\u6539<\/p>\n<hr \/>\n<p>\u76ee\u524d\u7b14\u8bb0\u5148\u505a\u5230\u8fd9\u91cc,\u5982\u679c\u6709\u9519\u518d\u66f4\u65b0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u8def\u7531\u7b80\u4ecb: \u8def\u7531\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8bbf\u95ee\u7684\u8def\u5f84,\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2aaction \u6bd4\u5982: \u8f93\u51fa\u89c6\u56fe Rout &hellip; <a href=\"https:\/\/7gugu.com\/index.php\/2018\/11\/29\/%e7%ac%94%e8%ae%b0laravel%e8%b7%af%e7%94%b1%e4%bd%bf%e7%94%a8%e7%ac%94%e8%ae%b0v1-0\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c[\u7b14\u8bb0][laravel]\u8def\u7531\u4f7f\u7528\u7b14\u8bb0v1.0\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,3,13],"tags":[],"class_list":["post-206","post","type-post","status-publish","format-standard","hentry","category-29","category-codetype","category-13"],"_links":{"self":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/comments?post=206"}],"version-history":[{"count":0,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/206\/revisions"}],"wp:attachment":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/media?parent=206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/categories?post=206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/tags?post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}