{"id":983,"date":"2024-04-16T04:14:12","date_gmt":"2024-04-15T19:14:12","guid":{"rendered":"http:\/\/inwelly.com\/?p=983"},"modified":"2024-04-16T04:14:12","modified_gmt":"2024-04-15T19:14:12","slug":"php-laravel-db-%ed%85%8c%ec%9d%b4%eb%b8%94-%eb%82%b4%ec%9a%a9-%ec%b6%9c%eb%a0%a5-1-2","status":"publish","type":"post","link":"https:\/\/inwelly.com\/?p=983","title":{"rendered":"PHP Laravel &#8211; DB \ud14c\uc774\ube14 \ub0b4\uc6a9 \ucd9c\ub825 1\/2"},"content":{"rendered":"\n<p>DB \ud14c\uc774\ube14 \uc0dd\uc131<\/p>\n\n\n\n<p>1)&nbsp; \ub9c8\uc774\uadf8\ub798\uc158 \ud30c\uc77c \ub9cc\ub4e4\uae30<\/p>\n\n\n\n<p>~\/www$&gt; php artisan make:migration create_test_table &#8211;create=test<\/p>\n\n\n\n<p>Created Migration: 2019_12_24_010708_create_test_table<\/p>\n\n\n\n<p>2) \uceec\ub7fc \ucd94\uac00 \ud3b8\uc9d1<\/p>\n\n\n\n<p>~\/www\/database\/migrations $&gt; vi&nbsp; 2019_12_24_010708_create_test_table.php<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;?php<\/p>\n\n\n\n<p>use&nbsp;Illuminate\\Database\\Migrations\\Migration;<\/p>\n\n\n\n<p>use&nbsp;Illuminate\\Database\\Schema\\Blueprint;<\/p>\n\n\n\n<p>use&nbsp;Illuminate\\Support\\Facades\\Schema;<\/p>\n\n\n\n<p>classCreateTestTableextendsMigration<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Run&nbsp;the&nbsp;migrations.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;void<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/p>\n\n\n\n<p>publicfunctionup()<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n\n\n\n<p>Schema::create(&#8216;test&#8217;,&nbsp;function&nbsp;(Blueprint$table)&nbsp;{<\/p>\n\n\n\n<p>$table-&gt;bigIncrements(&#8216;id&#8217;);<\/p>\n\n\n\n<p>$table-&gt;string(&#8216;subject&#8217;);<\/p>\n\n\n\n<p>$table-&gt;text(&#8216;contents&#8217;);<\/p>\n\n\n\n<p>$table-&gt;timestamps();<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Reverse&nbsp;the&nbsp;migrations.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;void<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/p>\n\n\n\n<p>publicfunctiondown()<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n\n\n\n<p>Schema::dropIfExists(&#8216;test&#8217;);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>}<\/p>\n<\/blockquote>\n\n\n\n<p>3) \ud3b8\uc9d1\ub41c \ud14c\uc774\ube14 \uc0dd\uc131~\/www$&gt; php artisan migrate<br>Migrating: 2019_12_24_010708_create_test_table<br>Migrated: 2019_12_24_010708_create_test_table (0.3 seconds)<\/p>\n\n\n\n<p>4) \ud14c\uc774\ube14 \ud655\uc778<\/p>\n\n\n\n<p>mysql&gt; desc test ;<\/p>\n\n\n\n<p>+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+<\/p>\n\n\n\n<p>| Field&nbsp; &nbsp; &nbsp; | Type&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Null | Key | Default | Extra&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<\/p>\n\n\n\n<p>+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+<\/p>\n\n\n\n<p>| id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| bigint(20) unsigned | NO&nbsp; &nbsp;| PRI | NULL&nbsp; &nbsp; | auto_increment |<\/p>\n\n\n\n<p>| subject&nbsp; &nbsp; | varchar(255)&nbsp; &nbsp; &nbsp; &nbsp; | NO&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp;| NULL&nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<\/p>\n\n\n\n<p>| contents&nbsp; &nbsp;| text&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | NO&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp;| NULL&nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<\/p>\n\n\n\n<p>| created_at | timestamp&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| YES&nbsp; |&nbsp; &nbsp; &nbsp;| NULL&nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<\/p>\n\n\n\n<p>| updated_at | timestamp&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| YES&nbsp; |&nbsp; &nbsp; &nbsp;| NULL&nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<\/p>\n\n\n\n<p>+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+<\/p>\n\n\n\n<p>5 rows in set (0.00 sec)<\/p>\n\n\n\n<p>5) \ucee8\ud2b8\ub864(Controller) \ud30c\uc77c \ub9cc\ub4e4\uae30&nbsp; ( \uc544\ub798 \uc635\uc158\uc744 \ud1b5\ud574 Test model \uac19\uc774 \ub9cc\ub4ec )<\/p>\n\n\n\n<p>~\/www$ php artisan make:controller TestController -r -m Test<\/p>\n\n\n\n<p>&nbsp;A App\\Test model does not exist. Do you want to generate it? (yes\/no) [yes]:<\/p>\n\n\n\n<p>&nbsp;&gt; yes<\/p>\n\n\n\n<p>Model created successfully.<\/p>\n\n\n\n<p>Controller created successfully.<br>6) \ucee8\ud2b8\ub864 \ud30c\uc77c(TestController.php)&nbsp; \ud3b8\uc9d1&nbsp;<br>~\/www\/app\/Http\/Controllers$ vi TestController.php<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;?php<\/p>\n\n\n\n<p>namespaceApp\\Http\\Controllers;<\/p>\n\n\n\n<p>use&nbsp;App\\Test;<\/p>\n\n\n\n<p>use&nbsp;Illuminate\\Http\\Request;<\/p>\n\n\n\n<p>classTestControllerextendsController<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Display&nbsp;a&nbsp;listing&nbsp;of&nbsp;the&nbsp;resource.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;\\Illuminate\\Http\\Response<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/p>\n\n\n\n<p>publicfunctionindex()<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n\n\n\n<p>returnview(&#8216;test.index&#8217;);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<\/blockquote>\n\n\n\n<p>7) \ub77c\uc6b0\ud130(routes) \uc758 web.php \ud30c\uc77c\uc5d0\uc11c URL \uc124\uc815<br>~\/www\/routes$ vi web.php<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;?php<\/p>\n\n\n\n<p>\/*<\/p>\n\n\n\n<p>|&#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;<\/p>\n\n\n\n<p>|&nbsp;Web&nbsp;Routes<\/p>\n\n\n\n<p>|&#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;<\/p>\n\n\n\n<p>|<\/p>\n\n\n\n<p>|&nbsp;Here&nbsp;is&nbsp;where&nbsp;you&nbsp;can&nbsp;register&nbsp;web&nbsp;routes&nbsp;for&nbsp;your&nbsp;application.&nbsp;These<\/p>\n\n\n\n<p>|&nbsp;routes&nbsp;are&nbsp;loaded&nbsp;by&nbsp;the&nbsp;RouteServiceProvider&nbsp;within&nbsp;a&nbsp;group&nbsp;which<\/p>\n\n\n\n<p>|&nbsp;contains&nbsp;the&nbsp;&#8220;web&#8221;&nbsp;middleware&nbsp;group.&nbsp;Now&nbsp;create&nbsp;something&nbsp;great!<\/p>\n\n\n\n<p>|<\/p>\n\n\n\n<p>*\/<\/p>\n\n\n\n<p>Route::get(&#8216;\/test&#8217;,&#8217;TestController@index&#8217;);<\/p>\n<\/blockquote>\n\n\n\n<p>8) http:\/\/\ub3c4\uba54\uc778\/test\u00a0 \u00a0\uc2e4\ud589\uc2dc \ubcf4\uc774\uac8c \ud558\ub294 view\u00a0 \ud30c\uc77c \ub9cc\ub4e4\uae30<br>~\/www\/resources\/views\/test$ vi index.blade.php<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;!DOCTYPEhtml&gt;&lt;html&gt;<\/p>\n\n\n\n<p>&lt;head&gt;<\/p>\n\n\n\n<p>&lt;title&gt;TEST&nbsp;PAGE&lt;\/title&gt;<\/p>\n\n\n\n<p>&lt;\/head&gt;<\/p>\n\n\n\n<p>&lt;body&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;TEST&nbsp;PAGE&nbsp;\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<p>&lt;\/body&gt;<\/p>\n\n\n\n<p>&lt;\/html&gt;<\/p>\n<\/blockquote>\n\n\n\n<p>9) http:\/\/\ub3c4\uba54\uc778\/test \ud655\uc778<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"919\" height=\"388\" src=\"http:\/\/inwelly.com\/wp-content\/uploads\/2024\/04\/image-483.png\" alt=\"\" class=\"wp-image-984\" style=\"width:838px;height:auto\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>DB \ud14c\uc774\ube14 \uc0dd\uc131 1)&nbsp; \ub9c8\uc774\uadf8\ub798\uc158 \ud30c\uc77c \ub9cc\ub4e4\uae30 ~\/www$&gt; php artisan make:migration create_test_table &#8211;create=test Created Migration: 2019_12_24_010708_create_test_table 2) \uceec\ub7fc \ucd94\uac00 \ud3b8\uc9d1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-983","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=983"}],"version-history":[{"count":1,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/983\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/983\/revisions\/985"}],"wp:attachment":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}