{"id":568,"date":"2021-07-17T18:04:53","date_gmt":"2021-07-17T18:04:53","guid":{"rendered":"http:\/\/robinluo.top\/?p=568"},"modified":"2021-07-17T18:05:07","modified_gmt":"2021-07-17T18:05:07","slug":"php-artisan-tinker","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=568","title":{"rendered":"php artisan tinker"},"content":{"rendered":"\n<p>\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u4ecb\u7ecd Laravel \u4e2d\u4e00\u4e2a\u4e0d\u592a\u4e3a\u4eba\u6240\u77e5\u7684\u529f\u80fd\uff0c\u6765\u5c55\u793a\u5982\u4f55\u5feb\u6377\u7684\u8c03\u8bd5\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u3002\u901a\u8fc7\u4f7f\u7528 Laravel artisan \u5185\u5efa\u7684&nbsp;<code>php artisan tinker<\/code>, \u6211\u4eec\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u770b\u5230\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u5e76\u4e14\u6267\u884c\u5404\u79cd\u60f3\u8981\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>Laravel artisan \u7684 tinker \u662f\u4e00\u4e2a\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Read%E2%80%93eval%E2%80%93print_loop\" target=\"_blank\">REPL (read-eval-print-loop)<\/a>\uff0cREPL \u662f\u6307\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u754c\u9762\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u8f93\u5165\u4e00\u6bb5\u4ee3\u7801\u53bb\u6267\u884c\uff0c\u5e76\u628a\u6267\u884c\u7ed3\u679c\u76f4\u63a5\u6253\u5370\u5230\u547d\u4ee4\u884c\u754c\u9762\u91cc\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ see the count of all users\r\nApp\\User::count();\r\n\r\n\/\/ find a specific user and see their attributes\r\nApp\\User::where('username', 'samuel')->first();\r\n\r\n\/\/ find the relationships of a user\r\n$user = App\\User::with('posts')->first();\r\n$user->posts;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>factory(App\\User::class, 10)->create();\nApp\\User::all();\nApp\\User::count();<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$user = new App\\User;\r\n$user->name = \"Wruce Bayne\";\r\n$user->email = \"iambatman@savegotham.com\";\r\n$user->save();<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>doc XXX<\/code><\/pre>\n\n\n\n<p>\u67e5\u9605\u67d0\u4e2a\u65b9\u6cd5\u7684\u6587\u6863<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>show XXX<\/code><\/pre>\n\n\n\n<p>\u663e\u793a\u67d0\u4e2a\u65b9\u6cd5\u7684\u4ee3\u7801<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u4ecb\u7ecd Laravel \u4e2d\u4e00\u4e2a\u4e0d\u592a\u4e3a\u4eba\u6240\u77e5\u7684\u529f\u80fd\uff0c\u6765\u5c55\u793a\u5982\u4f55\u5feb\u6377\u7684\u8c03\u8bd5\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u3002\u901a\u8fc7\u4f7f\u7528 Laravel artisan \u5185\u5efa\u7684&nbsp;php artisan tinker, \u6211\u4eec\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u770b\u5230\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u5e76\u4e14\u6267\u884c\u5404\u79cd\u60f3\u8981\u7684\u64cd\u4f5c\u3002 Laravel artisan \u7684 tinker \u662f\u4e00\u4e2a\u00a0REPL (read-eval-print-loop)\uff0cREPL \u662f\u6307\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u754c\u9762\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u8f93\u5165\u4e00\u6bb5\u4ee3\u7801\u53bb\u6267\u884c\uff0c\u5e76\u628a\u6267\u884c\u7ed3\u679c\u76f4\u63a5\u6253\u5370\u5230\u547d\u4ee4\u884c\u754c\u9762\u91cc\u3002 \u67e5\u9605\u67d0\u4e2a\u65b9\u6cd5\u7684\u6587\u6863 \u663e\u793a\u67d0\u4e2a\u65b9\u6cd5\u7684\u4ee3\u7801<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[10,95],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/568"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=568"}],"version-history":[{"count":2,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions"}],"predecessor-version":[{"id":570,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions\/570"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}