{"id":161,"date":"2021-08-10T22:51:02","date_gmt":"2021-08-10T13:51:02","guid":{"rendered":"https:\/\/kitayama.jp\/?p=161"},"modified":"2021-08-11T23:03:53","modified_gmt":"2021-08-11T14:03:53","slug":"laravel-vue-%e3%83%aa%e3%82%a2%e3%83%ab%e3%82%bf%e3%82%a4%e3%83%a0%e3%83%81%e3%83%a3%e3%83%83%e3%83%88%e3%82%92%e4%bd%9c%e3%82%8b","status":"publish","type":"post","link":"https:\/\/kitayama.jp\/?p=161","title":{"rendered":"Laravel vue \u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c1\u30e3\u30c3\u30c8\u3092\u4f5c\u308b"},"content":{"rendered":"\n<h3>Laravel\u3068Vue\u3067\u3001Line\u306e\u3088\u3046\u306a\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c1\u30e3\u30c3\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059<\/h3>\n\n\n\n<br>\n\n\n\n<strong>Laravel\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306f\u3001\u65e2\u306b\u4f5c\u3063\u3066\u3042\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002<\/strong>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan make:model Message -m<\/pre>\n\n\n\n<p><strong>\u4f5c\u6210\u3055\u308c\u305f\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306b\u4ee5\u4e0b\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u00a0    public function up()\n    {\n        Schema::create('messages', function (Blueprint $table) {\n            $table->bigIncrements('id');\n            $table->text('body'); \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u672c\u6587\n            $table->text('user');\n            $table->timestamps();\n        });\n    }<\/pre>\n\n\n\n<p><strong>\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php artisan migrate\n<\/pre>\n\n\n\n<p><strong>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u72b6\u6cc1\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/kitayama.jp\/wp-content\/uploads\/2021\/08\/scr001.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u30c7\u30fc\u30bf\u8ffd\u52a0\u306e\u6642\u306b\u30a8\u30e9\u30fc\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3001guarded \u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Message extends Model\n{\n    \/\/\n    protected $guarded = ['id'];\n}\n<\/pre>\n\n\n\n<h4>\u30c1\u30e3\u30c3\u30c8\u30da\u30fc\u30b8\u306e\u4f5c\u6210<\/h4>\n\n\n\n<p><strong>routes\/web.php \u306b route \u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Route::get('\/chat', 'ChatController@index');<\/code>\n<\/pre>\n\n\n\n<p><strong>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>php artisan make:controller ChatController<\/code><\/pre>\n\n\n\n<p>\u4f5c\u6210\u3057\u305f ChatController \u306b view\u306e\u8a2d\u5b9a\u3092\u3057\u307e\u3059\u3002\u30e6\u30fc\u30b6\u30fcID\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001\u30ed\u30b0\u30a4\u30f3\u5fc5\u9808\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u200b\n<code>public function __construct()\n{\n   $this-&gt;middleware('auth');\n}\npublic function index() {\n    return view('chat'); \/\/ \u30d5\u30a9\u30fc\u30e0\u30da\u30fc\u30b8\u306e\u30d3\u30e5\u30fc\n}<\/code>\n<\/pre>\n\n\n\n<h4>\u30d3\u30e5\u30fc\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/h4>\n\n\n\n<p>\u200b<strong>\u30d3\u30e5\u30fc\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html>\n&lt;body>\n    &lt;div id=\"chat\">\n        &lt;textarea v-model=\"message\">&lt;\/textarea>\n        &lt;br>\n        &lt;button type=\"button\" @click=\"send()\">\u9001\u4fe1&lt;\/button>\n        &lt;hr>\n        &lt;div v-for=\"m in messages\">\n            &lt;span v-text=\"m.created_at\">&lt;\/span>\n            &lt;span v-text=\"m.body\">&lt;\/span>\n        &lt;\/div>\n\n    &lt;\/div>\n    &lt;script src=\"\/js\/app.js\">&lt;\/script>\n    &lt;script>\n\n        new Vue({\n            el: '#chat',\n            data: {\n                message: '',\n                messages: []\n            },\n            methods: {\n                getMessages() {\n\n                    const url = '\/ajax\/chat';\n                    axios.get(url)\n                        .then((response) => {\n                            this.messages = response.data;\n                        });\n\n                },\n                send() {\n                    const url = '\/ajax\/chat';\n                    const params = { message: this.message };\n                    axios.post(url, params)\n                        .then((response) => {\n                            \/\/ \u6210\u529f\u3057\u305f\u3089\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u30af\u30ea\u30a2\n                            this.message = '';\n                        });\n                }\n            },\n            mounted() {\n                this.getMessages();\n                Echo.channel('chat')\n                    .listen('MessageCreated', (e) => {\n                        this.getMessages(); \/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u518d\u8aad\u8fbc\n                    });\n            }\n        });\n\n    &lt;\/script>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3>vue \u30a8\u30e9\u30fc<\/h3>\n\n\n\n<p>ERROR in .\/resources\/js\/components\/ExampleComponent.vue 1:0<br>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u5834\u5408\u3001<br>webpack.mix.js\u3000\u3092\u3000\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>mix.js(&#8216;resources\/js\/app.js&#8217;, &#8216;public\/js&#8217;).vue() \/\/ \u2b50\ufe0f \u8ffd\u8a18<br><br>\u3061\u306a\u307f\u306b\u3001pusher \u306f\u3001vuejs \u306f\u30012\u306b\u3057\u304b\u5bfe\u5fdc\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001vuejs \u306f\u3001ver2 \u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<br><br><strong>vuejs\u30d0\u30fc\u30b8\u30e7\u30f3\u30c1\u30a7\u30c3\u30af\u65b9\u6cd5<\/strong><br>npm list vue<br>vue-hoge@1.0.0 \/Users\/fuga\/project\/vue-hoge <br>\u2514\u2500\u2500 vue@2.6.10 <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u3068Vue\u3067\u3001Line\u306e\u3088\u3046\u306a\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30c1\u30e3\u30c3\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059 Laravel\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306f\u3001\u65e2\u306b\u4f5c\u3063\u3066\u3042\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002 \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 php artisan make:model Message -m \u4f5c\u6210\u3055\u308c\u305f\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306b\u4ee5\u4e0b\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0 \u00a0 public function up() { Schema::create(&#8216;messages&#8217;, function (Blueprint $table) { $table->big.. <a href=\"https:\/\/kitayama.jp\/?p=161\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/kitayama.jp\/index.php?rest_route=\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/kitayama.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kitayama.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kitayama.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kitayama.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":55,"href":"https:\/\/kitayama.jp\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/kitayama.jp\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/kitayama.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kitayama.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kitayama.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}