{"id":10499,"date":"2020-05-06T16:38:43","date_gmt":"2020-05-06T07:38:43","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=10499"},"modified":"2023-10-14T08:25:57","modified_gmt":"2023-10-13T23:25:57","slug":"%e3%80%90laravel%e3%80%91%e3%83%9e%e3%82%a4%e3%82%b0%e3%83%ac%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e5%9f%ba%e6%9c%ac","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=10499","title":{"rendered":"\u3010Laravel\u3011\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u57fa\u672c\u3001\u30e2\u30c7\u30eb\u306e\u57fa\u672c\uff08\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306a\u3069\uff09"},"content":{"rendered":"\n<p>phpMyAdmin\u304b\u3089\u624b\u52d5\u3067DLL\u306a\u3069\u3092\u5b9f\u884c\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u304c\u3001\u5404\u4eba\u304c\u624b\u52d5\u3067\u5b9f\u884c\u3059\u308b\u5834\u5408\u8a2d\u5b9a\u30df\u30b9\u306a\u3069\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3068\u3044\u3046\u5c02\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u5909\u66f4\u60c5\u5831\u3092git\u7ba1\u7406\u3057\u3066\u304a\u304d\u3001\u81ea\u52d5\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3053\u3068\u3067\u8a2d\u5b9a\u30df\u30b9\u3092\u9632\u3050\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c6\u30fc\u30d6\u30eb\u306e\u578b\u306e\u4f5c\u6210<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan make:migration create_\u30e2\u30c7\u30eb\u306e\u8907\u6570\u5f62(users\u7b49)_table<\/pre>\n\n\n\n<p>\u3059\u308b\u3068<span style=\"color: #ff0000;\"><strong>\u300cdatabase\/migrations\u300d<\/strong><\/span>\u306e\u76f4\u4e0b\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreateTestsTable extends Migration\n{\n    \/**\n     * Run the migrations.\n     *\n     * @return void\n     *\/\n    public function up()\n    {\n        Schema::create('tests', function (Blueprint $table) {\n            $table-&gt;bigIncrements('id');\n            $table-&gt;timestamps();\n        });\n    }\n\n    \/**\n     * Reverse the migrations.\n     *\n     * @return void\n     *\/\n    public function down()\n    {\n        Schema::dropIfExists('tests');\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u30ab\u30e9\u30e0\u4fee\u98fe\u5b50<\/th><th>\u8aac\u660e<\/th><\/tr><tr><td>\n<p class=\"p1\">bigIncrements('\u540d\u524d')<\/p>\n<\/td><td>\u81ea\u52d5\u63a1\u756a\u3057\u307e\u3059\u3002\u4e3b\u30ad\u30fc\u7b49\u306b\u4ed8\u3051\u3066<span style=\"color: #ff0000;\"><strong>\u81ea\u52d5\u7684\u306b\u4e3b\u30ad\u30fc\u9078\u5b9a<\/strong><\/span>\u3055\u308c\u307e\u3059\u3002<\/td><\/tr><tr><td>string('\u540d\u524d',\u6587\u5b57\u6570)<\/td><td>\u6587\u5b57\u5217\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/td><\/tr><tr><td>longText('\u540d\u524d')<\/td><td>string\u3088\u308a\u9577\u3044\u6587\u5b57\u6570\u306e\u6570\u5b57\u3092\u683c\u7d0d\u3067\u304d\u307e\u3059\u3002<\/td><\/tr><tr><td>boolan('\u540d\u524d')<\/td><td>true\/false\u3092\u683c\u7d0d\u3067\u304d\u307e\u3059\u3002<\/td><\/tr><tr><td>tinyInteger('\u540d\u524d')<\/td><td>\u5c11\u306a\u3044\u6570\u5b57\u3092\u683c\u7d0d\u3067\u304d\u307e\u3059\u3002<\/td><\/tr><tr><td>timestamps()<\/td><td>\u65e5\u6642\u3092\u683c\u7d0d\u3067\u304d\u307e\u3059\u3002<\/td><\/tr><tr><td>primary()<\/td><td><span style=\"color: #ff0000;\"><strong>\u4e3b\u30ad\u30fc\u3092id\u4ee5\u5916\u7b49\u306e\u4ed6\u306b\u8a2d\u5b9a\u3057\u305f\u3044\u5834\u5408\u3084\u8907\u5408\u30ad\u30fc\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u5834\u5408<\/strong><\/span>\u7b49\u306b\u4f7f\u3044\u307e\u3059\u3002<\/td><\/tr><tr><td><\/td><td><\/td><\/tr><tr><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u30ab\u30e9\u30e0\u4fee\u98fe\u5b50<\/h2>\n\n\n\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30ab\u30e9\u30e0\u30bf\u30a4\u30d7(string)\u306e\u5148\u306b\u6307\u5b9a\u3067\u304d\u308b\u4fee\u98fe\u5b50\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$table-&gt;string('\u540d\u524d',20)-&gt;nullable();<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u30ab\u30e9\u30e0\u4fee\u98fe\u5b50<\/th><th>\u8aac\u660e<\/th><\/tr><tr><td>nullable()<\/td><td>NULL\u3092\u8a31\u53ef\u3057\u307e\u3059\u3002<\/td><\/tr><tr><td>unsigned()<\/td><td>\u30de\u30a4\u30ca\u30b9\u304c\u306a\u3044\u30d7\u30e9\u30b9\u3060\u3051\u306e\u5024\u3092\u683c\u7d0d\u3055\u305b\u307e\u3059\u3002<\/td><\/tr><tr><td><\/td><td><\/td><\/tr><tr><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan migrate<\/pre>\n\n\n\n<p>\u5b9f\u969b\u306b\u3001\u4e0a\u8a18\u3067\u7528\u610f\u3057\u305f\u578b\u306b\u57fa\u3065\u3044\u3066\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan make:migration add_\u8ffd\u52a0\u30ab\u30e9\u30e0\u540d_to_\u30c6\u30fc\u30d6\u30eb\u540d(users\u7b49)_table --table=\u30c6\u30fc\u30d6\u30eb\u540d(users\u7b49)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4fee\u98fe\u5b50<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u4fee\u98fe\u5b50<\/th><th>\u8aac\u660e<\/th><\/tr><tr><td>\n<div>\n<div>after('\u5f8c\u308d\u306b\u8ffd\u52a0\u3057\u305f\u3044\u30ab\u30e9\u30e0\u540d')<\/div>\n<\/div>\n<\/td><td>\u6307\u5b9a\u3057\u305f\u30ab\u30e9\u30e0\u540d\u306e\u5f8c\u308d\u306b\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/td><\/tr><tr><td><\/td><td><\/td><\/tr><tr><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3059\u308b\u3002<\/h2>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u8a18\u8ff0\u3092\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">    public function down()\n    {\n        Schema::table('\u30c6\u30fc\u30d6\u30eb\u540d(users\u7b49\uff09', function (Blueprint $table) {\n            $table-&gt;dropColumn('\u30ab\u30e9\u30e0\u540d');\n        });\n    }<\/pre>\n\n\n\n<p>\u305d\u306e\u5f8c\u306b\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan migrate:rollback<\/pre>\n\n\n\n<p>\u8907\u6570\u56de\u623b\u3057\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u306e<span style=\"color: #ff0000;\"><strong>step\u30aa\u30d7\u30b7\u30e7\u30f3<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">--step \u56de\u6570<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u9069\u7528\u72b6\u614b\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/h2>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u9069\u7528\u72b6\u614b\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u5b9f\u884c\u3057\u3066\u3044\u306a\u3044\u3082\u306e\u306b\u95a2\u3057\u3066\u306fRan?\u304c\u300cNo\u300d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate:status<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5916\u90e8\u30ad\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u306b\u306f\uff1f<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">$table-&gt;foreign('\u5f93\u30c6\u30fc\u30d6\u30eb\u5074\u306e\u30ad\u30fc')-&gt;references('\u4e3b\u30c6\u30fc\u30d6\u30eb\u5074\u306e\u30ad\u30fc')-&gt;on('\u4e3b\u30c6\u30fc\u30d6\u30eb\u30c6\u30fc\u30d6\u30eb\u540d(users\u7b49)');<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u30e2\u30c7\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210<\/h2>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5f8c\u306b\u30e2\u30c7\u30eb\u3082\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\uff08\u540c\u6642\u306b\u4f5c\u6210\u3082\u3067\u304d\u307e\u3059\u304c\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan make:model \u30e2\u30c7\u30eb\u540d<\/pre>\n\n\n\n<p>\u3059\u308b\u3068\u4e0b\u8a18\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bPHP\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">app\/\u30e2\u30c7\u30eb\u540d.php<\/pre>\n\n\n\n<p>\u5b9f\u969b\u306e\u958b\u767a\u3067\u306fModels\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u305d\u306e\u4e0b\u306b\u305f\u304f\u3055\u3093\u306e\u30e2\u30c7\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u6253\u3061\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan make:model Models\/\u30e2\u30c7\u30eb\u540d<\/pre>\n\n\n\n<p>\u300c\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u300d\u3068\u300c\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u300d\u3092\u307e\u3068\u3081\u3066\u4f5c\u6210\u3057\u305f\u3044\u5834\u5408\u306f<span style=\"color: #ff0000;\"><strong>\u300c-mc\u300d<\/strong><\/span>\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan make:model Models\/\u30e2\u30c7\u30eb\u540d -mc<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">-m<\/h3>\n\n\n\n<p>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u540c\u6642\u306b\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">-c<\/h3>\n\n\n\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u30d5\u30a1\u30a4\u30eb\u3092\u540c\u6642\u306b\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">tinker<\/h3>\n\n\n\n<p>DB\u3068\u7c21\u6613\u7684\u306b\u63a5\u7d9a\u3057\u3001\u5bfe\u8a71\u7684\u306bDB\u3068\u3084\u308a\u53d6\u308a\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f7f\u3044\u65b9<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">$test = new App\\Models\\Test;\n$test-&gt;text = \"aaa\"; \/\/\u30e2\u30c7\u30eb\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3002\n$test-&gt;save(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/DB\u306b\u4fdd\u5b58\u3059\u308b\u3002\nApp\\Models\\Test::all(); \/\/\u767b\u9332\u3057\u305f\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u3002\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u300c1:\u591a\u300d\u306e\u30e2\u30c7\u30eb\u306e\u5b9a\u7fa9\u306e\u4ed5\u65b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e3b\u30c6\u30fc\u30d6\u30eb\u306e\u65b9<\/h3>\n\n\n\n<p><span style=\"color: #ff0000;\"><strong>hasMany\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class \u4e3b\u30c6\u30fc\u30d6\u30eb\u306e\u30e2\u30c7\u30eb extends Model\n{\n   public function \u526f\u30c6\u30fc\u30d6\u30eb\u540d\u8907\u6570\u5f62(users\u7b49)(){\n       return $this->hasMany('app\\Models\\\u526f\u30e2\u30c7\u30eb(User\u7b49)',\u5916\u90e8\u30ad\u30fc,\u81ea\u30e2\u30c7\u30eb\u306e\u4e3b\u30ad\u30fc);\n   }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u81ea\u30e2\u30c7\u30eb\u306e\u4e3b\u30ad\u30fc<\/h4>\n\n\n\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u306fid\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u526f\u30c6\u30fc\u30d6\u30eb\u306e\u65b9<\/h3>\n\n\n\n<p><span style=\"color: #ff0000;\"><strong>belongsTo\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Shop extends Model\n{\n    public function \u4e3b\u30c6\u30fc\u30d6\u30eb\u306e\u5358\u6570\u7cfb(user\u7b49)(){\n        return $this->belongsTo('App\\Models\\\u4e3b\u30c6\u30fc\u30d6\u30eb(user)',\u5916\u90e8\u30ad\u30fc,\u89aa\u30e2\u30c7\u30eb\u306e\u4e3b\u30ad\u30fc);\n    }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u300c\u591a:\u591a\u300d\u306e\u30e2\u30c7\u30eb\u306e\u5b9a\u7fa9\u306e\u4ed5\u65b9<\/h2>\n\n\n\n<p>\u591a\u30c6\u30fc\u30d6\u30eb\u306e\u9593\u306b<span style=\"color: #ff0000;\"><strong>\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210<\/strong><\/span>\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u591a\u30c6\u30fc\u30d6\u30eb\u306e\u65b9<\/h3>\n\n\n\n<p>\u591a\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u3069\u3061\u3089\u3082<span style=\"color: #ff0000;\"><strong>belongsToMany\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u76f8\u624b\u306e\u591a\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u5b9a\u3059\u308b<\/strong><\/span>\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class \u5f93\u30c6\u30fc\u30d6\u30eb\u540d extends Model\n{\n    public function \u5bfe\u3068\u306a\u308b\u5f93\u30c6\u30fc\u30d6\u30eb\u540d(users\u7b49)(){\n        return $this->belongsToMany('App\\Models\\\u5bfe\u3068\u306a\u308b\u5f93\u30c6\u30fc\u30d6\u30eb',\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u540d,\u81ea\u30e2\u30c7\u30eb\u306e\u5916\u90e8\u30ad\u30fc,\u95a2\u9023\u3059\u308b\u30e2\u30c7\u30eb\u306e\u5916\u90e8\u30ad\u30fc)->withTimeStamps();\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u540d<\/h4>\n\n\n\n<p>\u81ea\u30e2\u30c7\u30eb\u3068\u95a2\u9023\u3059\u308b\u30e2\u30c7\u30eb\u305d\u308c\u305e\u308c\u306e\u30e2\u30c7\u30eb\u540d\u3092\u30b9\u30cd\u30fc\u30af\u30b1\u30fc\u30b9\u306b\u3057\u3066\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\u306b\u4e26\u3079\u3066\u3064\u306a\u3052\u305f\u3082\u306e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">withTimeStamps<\/h4>\n\n\n\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3060\u3068\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u306b\u5024\u304c\u5165\u3063\u305f\u969b\u306bcreated_at\u3068update_at\u306f\u81ea\u52d5\u66f4\u65b0\u3055\u308c\u307e\u305b\u3093\u3002\u81ea\u52d5\u66f4\u65b0\u3055\u308c\u3066\u307b\u3057\u3044\u5834\u5408\u306f\u3001\u3053\u308c\u3092\u5b9a\u7fa9\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3002<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\uff11\uff1a\u591a\u306e\u5834\u5408<\/h3>\n\n\n\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u6307\u5b9a\u3059\u308c\u3070\u4e3b\u30c6\u30fc\u30d6\u30eb\u306b\u7d10\u3065\u304f\u526f\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u914d\u5217\u5f62\u5f0f\u3067\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">use App\\Models\\\u4e3b\u30c6\u30fc\u30d6\u30eb;\nuse App\\Models\\\u526f\u30c6\u30fc\u30d6\u30eb;\n\n$\u5909\u6570\uff08\u914d\u5217\u3067\u53d6\u5f97\u3067\u304d\u308b\uff09 = \u4e3b\u30c6\u30fc\u30d6\u30eb::find(1)-&gt;\u526f\u30c6\u30fc\u30d6\u30eb(users\u7b49\u306e\u8907\u6570\u5f62);\n<\/pre>\n\n\n\n<p><span style=\"color: #ff0000;\"><strong>\u4e3b\u30c6\u30fc\u30d6\u30eb\u3068\u526f\u30c6\u30fc\u30d6\u30eb\u3092\u9006\u306b\u3057\u3066\u3082\u554f\u984c\u306a\u304f\u7d10\u3065\u304f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u591a\uff1a\u591a\u306e\u5834\u5408<\/h3>\n\n\n\n<p>\u591a\uff1a\u591a\u306e\u5834\u5408\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u6307\u5b9a\u3059\u308c\u3070\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u4e3b\u30c6\u30fc\u30d6\u30eb::find(1)-&gt;\u526f\u30c6\u30fc\u30d6\u30eb()-&gt;get()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u3059\u3067\u306b\u5b58\u5728\u3059\u308b\u30c7\u30fc\u30bf\u540c\u58eb\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u7d50\u3076\u3002<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1:\u591a\u306e\u5834\u5408<\/h3>\n\n\n\n<p>\u3059\u3067\u306b\u5b58\u5728\u3059\u308b\u30c7\u30fc\u30bf\u540c\u58eb\u3092\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u7d50\u3076\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\uff08\u3082\u3061\u308d\u3093\u624b\u52d5\u3067\u3082\u53ef\u80fd\u3067\u3059\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5b50\u30e2\u30c7\u30eb\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9->\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u540d()->associate(\u89aa\u30e2\u30c7\u30eb\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9 or \u5916\u90e8\u30ad\u30fc)<\/code><\/pre>\n\n\n\n<p>\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002(categoryid\uff1d2\u306b\u5bfe\u3057\u3066blog\u306eid=1\u3092\u7d10\u3065\u3051\u3066\u3044\u308b\u3002)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Blog::find(1)->category()->associate(2);<\/code><\/pre>\n\n\n\n<p>\u307e\u305f\u3001\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u95a2\u4fc2\u3092\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u306f\u9006\u306bdissociate\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u591a\uff1a\u591a\u306e\u5834\u5408<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\u30e2\u30c7\u30eb\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9->\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u540d()->attach(\u76f8\u624b\u30e2\u30c7\u30eb\u306e\u5916\u90e8\u30ad\u30fc)<\/code><\/pre>\n\n\n\n<p>\u4e2d\u9593\u30c6\u30fc\u30d6\u30eb\u3092\u610f\u8b58\u305b\u305a\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002\uff08blogid=1\u306e\u30c7\u30fc\u30bf\u3092categoryid=2,4\u306b\u7d10\u3065\u3051\u3066\u3044\u308b\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Blog::find(1)->category()->attach(&#91;2,4]);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"phpMyAdmin\u304b\u3089\u624b\u52d5\u3067DLL\u306a\u3069\u3092\u5b9f\u884c\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u304c\u3001\u5404\u4eba\u304c\u624b\u52d5\u3067\u5b9f\u884c\u3059\u308b\u5834\u5408\u8a2d\u5b9a\u30df\u30b9\u306a\u3069\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3068\u3044\u3046\u5c02\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u5909\u66f4\u60c5\u5831\u3092git\u7ba1 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10499"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10499"}],"version-history":[{"count":23,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10499\/revisions"}],"predecessor-version":[{"id":23689,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10499\/revisions\/23689"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10499"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}