{"id":1564,"date":"2025-02-22T15:58:21","date_gmt":"2025-02-22T07:58:21","guid":{"rendered":"https:\/\/blog.nonot.cn\/?p=1564"},"modified":"2025-02-22T15:58:21","modified_gmt":"2025-02-22T07:58:21","slug":"laravel-%e8%b0%83%e8%af%95","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2025\/02\/22\/laravel-%e8%b0%83%e8%af%95\/","title":{"rendered":"Laravel \u8c03\u8bd5"},"content":{"rendered":"<p>\u4e00\u3001\u8def\u7531 php artisan route:list<\/p>\n<pre>routes\/web.php\r\nRoute::get('\/lin', function () {\r\n    echo \"nihao lin\";\r\n});\r\n\/\/1.\u8def\u7531\u53c2\u6570 \uff0c\u53ef\u9009\u591a\u4e2a\u95ee\u53f7{id?}\r\n\/\/http:\/\/www.laravel02.com\/user\/111\r\nRoute::get('user\/{id?}', function ($id = 0) {\r\n    echo \"nihao\".$id;\r\n});\r\n\/\/1.1\u901a\u8fc7?\u5f62\u5f0f\u6765\u4f20\u9012\u53c2\u6570\uff0c\u4e0d\u9700\u8981\u5199\u8def\u7531\r\n\/\/http:\/\/www.laravel02.com\/test?id=111\r\nRoute::any('test', function () {\r\n    echo \"nihao\".$_GET['id'];\r\n});\r\n\/\/2.\u8def\u7531\u7c7b\u578b\r\nRoute::match(['get', 'post'], '\/purchase', function(){});\r\nRoute::any('foo',function(){});\r\n\/\/3.\u8def\u7531\u522b\u540d\r\nRoute::any('test2', function () {\r\n    echo \"nihao\".$_GET['id'];\r\n})-&gt;name('\u65b0\u540d\u5b57');\r\n\/\/\u8c03\u7528\u8def\u7531\uff1aroute('\u65b0\u540d\u5b57');\r\n\r\n\/\/4.\u8def\u7531\u7fa4\u7ec4 admin\r\nRoute::group(['prefix'=&gt;'admin'],function(){\r\n    Route::get('test1', function () {\r\n        \/\/\u5339\u914d \/admin\/test1\r\n        echo \"\/admin\/test1\";\r\n    });\r\n    Route::any('\/test2', function () {\r\n        \/\/\u5339\u914d \/admin\/test2\r\n    });\r\n});<\/pre>\n<p>\u4e8c\u3001php artisan make:controller \u63a7\u5236\u5668\u540d \uff08\u5927\u9a7c\u5cf0\uff09+Controller<\/p>\n<p>1.\u63a7\u5236\u5668\u751f\u6210\uff1a<\/p>\n<p>php artisan make:controller TestController<\/p>\n<pre>&lt;?php\r\n\r\nnamespace AppHttpControllers;\r\n\r\nuse IlluminateHttpRequest;\/\/\u547d\u540d\u7a7a\u95f4\u7684\u4e09\u5143\u7d20\uff1a\u5e38\u91cf\uff0c\u65b9\u6cd5\u548c\u7c7b\r\n\r\nclass TestController extends Controller\r\n{\r\n    public function test1(){\r\n        phpinfo();\r\n    }\r\n}<\/pre>\n<p>2.\u63a7\u5236\u5668\u8def\u7531\uff1a<\/p>\n<p>\u4f7f\u7528\u8def\u7531\u89c4\u5219\u8c03\u7528\u63a7\u5236\u5668\u4e0b\u7684\u65b9\u6cd5\uff0c\u975e\u56de\u8c03\u51fd\u6570<\/p>\n<p>\u201c\u63a7\u5236\u5668\u7c7b\u540d@\u65b9\u6cd5\u540d\u201d<\/p>\n<pre>\/\/ \u5b9e\u6218\u6d4b\u8bd5\r\n<span style=\"color: #ff6600;\">Route::get('\/home\/test\/test1','TestController@test1');<\/span>\r\n\u4e0a\u9762\u8c03\u8bd5\u672a\u901a\u8fc7\uff0c\u4e0b\u9762\u901a\u8fc7\uff1a\r\n<span style=\"color: #ff6600;\">Route::get('\/home\/test\/test1',[TestController::class,'test1']);<\/span>\r\n<a href=\"http:\/\/www.laravel02.com\/home\/test\/test1\" rel=\"noopener nofollow\">http:\/\/www.laravel02.com\/home\/test\/test1\r\n\r\n<\/a><\/pre>\n<p>3. \u5206\u76ee\u5f55\u7ba1\u7406, \u547d\u4ee4\u91cc\u589e\u52a0\u76ee\u5f55\u540d\u5373\u53ef\uff1a<\/p>\n<p>E:phpStudyPHPTutorialWWWlaravel02&gt;php artisan make:controller Home\/IndexController<\/p>\n<p>E:phpStudyPHPTutorialWWWlaravel02&gt;php artisan make:controller Admin\/IndexController<\/p>\n<pre>\/\/home\u76ee\u5f55 index \u7c7b\u7684index\u65b9\u6cd5\r\nRoute::get('\/home\/index\/index','HomeIndexController@index');\r\nRoute::get('\/admin\/index\/index','AdminIndexController@index');\r\n<a href=\"http:\/\/www.laravel02.com\/admin\/index\/index\" rel=\"noopener nofollow\">http:\/\/www.laravel02.com\/home\/index\/index<\/a>\r\n<a href=\"http:\/\/www.laravel02.com\/admin\/index\/index\" rel=\"noopener nofollow\">http:\/\/www.laravel02.com\/admin\/index\/index<\/a><\/pre>\n<p>4. \u63a5\u6536\u7528\u6237\u8f93\u5165<\/p>\n<p>\u63a5\u6536\u7528\u6237\u8f93\u5165\u7684\u7c7b\uff1aIlluminateSupportFacadesInput<\/p>\n<p>Facades \u662f\u7c7b\u7684\u4e00\u4e2a\u63a5\u53e3\u5b9e\u73b0\uff0c\u7b97\u9759\u6001\u65b9\u6cd5<\/p>\n<p>Input::get();<\/p>\n<p>Input::all();<\/p>\n<p>input::only([])<\/p>\n<p>input::except([])<\/p>\n<p>\u7b80\u5316 use IlluminateSupportFacadesInput \uff0c\u7ed9\u5b83\u6dfb\u52a0\u522b\u540d<\/p>\n<p><a style=\"font-family: Consolas, Monaco, monospace;\" href=\"http:\/\/www.laravel02.com\/admin\/index\/index\" rel=\"noopener nofollow\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1568\" title=\"506173-20200925161257316-665478840-2\" src=\"https:\/\/blog.nonot.cn\/wp-content\/uploads\/replace\/c365e77ed65a140f118c4181efb699a6.png\" alt=\"506173-20200925161257316-665478840-2\" width=\"550\" height=\"866\" \/><\/a><span class=\"wbspy-placeholder-tip\" style=\"position: absolute; top: 50%; left: 0px; width: 100%; text-align: center; line-height: 20px; font-size: 16px; margin-top: -10px; display: inline !important;\"><br \/>\n<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre>\u6d4b\u8bd5\uff1a\r\nRoute::get('\/home\/test\/test2','TestController@test2');<\/pre>\n<pre><a href=\"http:\/\/www.laravel02.com\/home\/test\/test2?ddd=aaaa&amp;id=112&amp;name=zhangsan\" rel=\"noopener nofollow\">http:\/\/www.laravel02.com\/home\/test\/test2?ddd=aaaa&amp;id=112&amp;name=zhangsan<\/a>\r\n&lt;?php\r\n\r\nnamespace AppHttpControllers;\r\n\r\nuse IlluminateHttpRequest;\/\/\u547d\u540d\u7a7a\u95f4\u7684\u4e09\u5143\u7d20\uff1a\u5e38\u91cf\uff0c\u65b9\u6cd5\u548c\u7c7b\r\n\/\/use IlluminateSupportFacadesInput;\r\nuse Input;\r\n\r\nclass TestController extends Controller\r\n{\r\n    public function test1(){\r\n        phpinfo();\r\n    }\r\n    \/\/\u6d4b\u8bd5input\r\n    public function test2(){\r\n        \/\/\u83b7\u53d6\u4e00\u4e2a\u503c\uff0c\u5982\u679c\u6ca1\u503c\u9ed8\u8ba4\u7b2c\u4e8c\u4e2a\u53c2\u6570\r\n        echo Input::get('id',\"10086\");\r\n        \/\/\u83b7\u53d6\u5168\u90e8\uff08\u6570\u7ec4\u683c\u5f0f\uff09\r\n        $all = Input::all();\r\n        \/\/dump + die ,\u540e\u7eed\u4ee3\u7801\u4e0d\u4f1a\u6267\u884c\r\n\/\/        dd($all);\r\n        \/\/\u83b7\u53d6\u6307\u5b9a\u4fe1\u606f(\u5b57\u7b26\u4e32\u683c\u5f0f)\r\n\/\/        dd(Input::get('name'));\r\n        \/\/\u83b7\u53d6\u6307\u5b9a\u51e0\u4e2akey\uff08\u6570\u7ec4\u683c\u5f0f\uff09\r\n\/\/        dd(Input::only(['id','name']));\r\n        \/\/\u83b7\u53d6\u6307\u5b9a\u51e0\u4e2akey\u4e4b\u5916\u7684\u503c\uff08\u6570\u7ec4\u683c\u5f0f\uff09\r\n\/\/        dd(Input::except(['name']));\r\n        \/\/\u5224\u65adkey\u662f\u5426\u5b58\u5728(boole)\r\n        dd(Input::has('name'));\r\n    }\r\n}<\/pre>\n<pre>\u8f93\u51fa\uff1a\r\n112<\/pre>\n<pre class=\"sf-dump\" data-indent-pad=\"  \"><span class=\"sf-dump-note\">array:1 [<a class=\"sf-dump-ref sf-dump-toggle\" title=\"[Ctrl+click] Expand all children\">\u25bc<\/a><samp class=\"sf-dump-expanded\" data-depth=\"1\">\r\n  \"<span class=\"sf-dump-key\">id\" =&gt; \"<span class=\"sf-dump-str\" title=\"3 characters\">112\"\r\n<\/span><\/span><\/samp>]<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u8def\u7531 php artisan route:list ro&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1564","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/1564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1564"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/1564\/revisions"}],"predecessor-version":[{"id":1570,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/1564\/revisions\/1570"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}