{"id":994,"date":"2024-04-16T04:59:49","date_gmt":"2024-04-15T19:59:49","guid":{"rendered":"http:\/\/inwelly.com\/?p=994"},"modified":"2024-04-16T04:59:49","modified_gmt":"2024-04-15T19:59:49","slug":"php-laravel-6-crud-%ea%b8%b0%eb%b3%b8-with-mysql-%ed%85%8c%ec%9d%b4%eb%b8%94-%ec%83%9d%ec%84%b1-1","status":"publish","type":"post","link":"https:\/\/inwelly.com\/?p=994","title":{"rendered":"PHP Laravel 6 &#8211; CRUD \uae30\ubcf8 with mysql &#8211; \ud14c\uc774\ube14 \uc0dd\uc131 (1)"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>$&gt; php artisan &#8211;version<\/p>\n\n\n\n<p>Laravel Framework 6.9.0<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>1. \ud14c\uc774\ube14 \uc0dd\uc131 \ubc0f \ubaa8\ub378 \ud30c\uc77c \uc0dd\uc131\n- \uc0dd\uc131\uc5d0 \uc55e\uc11c \".env\" \ud30c\uc77c\uc5d0 \uc790\uc2e0\uc774 \uc0ac\uc6a9 \ud558\ub294 DB \uc5d0 \ub9de\uac8c \uc124\uc815\ud55c\ub2e4. \n\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=test_db\nDB_USERNAME=test_user\nDB_PASSWORD=test_passwd\n\n- \uc2e4\ud589 1 : \ud30c\uc77c\uc0dd\uc131\n$> php artisan make:model TestCRUD -m\nModel created successfully.\nCreated Migration: 2020_01_03_011220_create_test_c_r_u_d_s_table\n\n- \ud655\uc778 1 : \uc0dd\uc131\ub41c \ud30c\uc77c for DB \ud14c\uc774\ube14\n$> cd \/database\/migrations\n2020_01_03_011220_create_test_c_r_u_d_s_table.php<\/code><\/pre>\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>classCreateTestCRUDSTableextendsMigration<\/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_c_r_u_d_s&#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;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_c_r_u_d_s&#8217;);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>}<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>\uc704 \ub0b4\uc6a9\uc744 \uc544\ub798\uc640 \uac19\uc774 \ubcc0\uacbd \ud558\uc790 \n\ubcc0\uacbd\ub0b4\uc6a9\uc740 \n- \ud14c\uc774\ube14\uc5d0 \ucd94\uac00\ub418\ub294 \uceec\ub7fc \ucd94\uac00 \n            $table->string('title', 100);\n            $table->text('description')->nullable();\n- \ud14c\uc774\ube14\uba85 \ubcc0\uacbd\n            test_c_r_u_d_s => test_tab<\/code><\/pre>\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>classCreateTestCRUDSTableextendsMigration<\/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_tab&#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><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">$table->string(&#8216;title&#8217;,\u00a0100);<\/mark><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">$table->text(&#8216;description&#8217;)->nullable();<\/mark><\/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;<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">test_tab<\/mark>&#8216;);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p>}<\/p>\n<\/blockquote>\n\n\n\n<p>&#8211; \uc2e4\ud589 2 : \ud14c\uc774\ube14 \uc0dd\uc131<\/p>\n\n\n\n<p>$&gt; php artisan migrate<\/p>\n\n\n\n<p>Migrating: 2020_01_03_011220_create_test_c_r_u_d_s_table<\/p>\n\n\n\n<p>Migrated:&nbsp; 2020_01_03_011220_create_test_c_r_u_d_s_table (0.11 seconds)<\/p>\n\n\n\n<p>&#8211; \ud655\uc778 2 : \uc0dd\uc131\ub41c \ud14c\uc774\ube14<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"197\" src=\"http:\/\/inwelly.com\/wp-content\/uploads\/2024\/04\/image-486.png\" alt=\"\" class=\"wp-image-995\" style=\"width:920px;height:auto\"\/><\/figure>\n\n\n\n<p>&#8211; \ud655\uc778 3 :\uc0dd\uc131\ub41c \ubaa8\ub378 \ud30c\uc77c&nbsp;<br>$&gt; cd \/app<br>TestCRUD.php&nbsp;<\/p>\n\n\n\n<p>&#8211; \ubaa8\ub378 \ud30c\uc77c \ud3b8\uc9d1<\/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;<\/p>\n\n\n\n<p>use&nbsp;Illuminate\\Database\\Eloquent\\Model;<\/p>\n\n\n\n<p>classTestCRUDextendsModel<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>\/\/<\/p>\n\n\n\n<p>}<\/p>\n<\/blockquote>\n\n\n\n<p>\ud3b8\uc9d1 \uc544\ub798\u00a0\u00a0<\/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;<\/p>\n\n\n\n<p>use&nbsp;Illuminate\\Database\\Eloquent\\Model;<\/p>\n\n\n\n<p>classTestCRUDextendsModel<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">protected $table = &#8216;test_tab&#8217;;\u00a0<\/mark> \u00a0 \/\/ \uc124\uba85\uc758 \ud3b8\uc758\uc640 \uc774\ud574\ub97c \ub3d5\uace0\uc790 default table name \ubcc0\uacbd<br>\/\/ ( Default table \uacbd\uc6b0 \ud574\ub2f9 \ub77c\uc778\uc740 \uc0ac\uc6a9 \ud558\uc9c0 \uc54a\uc544\ub3c4 \ub41c\ub2e4 )<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-red-color\">protected\u00a0$fillable\u00a0=\u00a0[&#8216;title&#8217;,\u00a0&#8216;description&#8217;];<\/mark><\/p>\n\n\n\n<p>}<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>$&gt; php artisan &#8211;version Laravel Framework 6.9.0 &lt;?php use&nbsp;Illuminate\\Database\\Migrations\\Migration; use&nbsp;Illuminate\\Database\\Schema\\Blueprint; use&nbsp;Illuminate\\Support\\Facades\\Schema; classCreateTestCRUDSTableextendsMigration { \/** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Run&nbsp;the&nbsp;migrations. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ publicfunctionup() &nbsp;&nbsp;&nbsp;&nbsp;{ [&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-994","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/994","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=994"}],"version-history":[{"count":1,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":996,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/994\/revisions\/996"}],"wp:attachment":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}