{"id":7231,"date":"2020-05-01T15:00:36","date_gmt":"2020-05-01T06:00:36","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=7231"},"modified":"2020-04-29T05:45:15","modified_gmt":"2020-04-28T20:45:15","slug":"laravel%e3%81%a7%e3%80%8c%e3%81%84%e3%81%84%e3%81%ad%ef%bc%81%e3%80%8d%e6%a9%9f%e8%83%bd%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b%ef%bc%88%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89%e5%8f%af","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=7231","title":{"rendered":"Laravel\u3067\u300c\u3044\u3044\u306d\uff01\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4eca\u56de\u306f\u5c11\u3057\u524d\u306b\u516c\u958b\u3057\u305f\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=7148\">\u3010Laravel\u3011\u30d5\u30a1\u30a4\u30eb\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6a5f\u80fd\u3092\u3064\u304f\u308b\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09<\/a>\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3068\u540c\u3058\u304f<strong>\u300c\u8a18\u4e8b\u306b\u3057\u3066\u306a\u304b\u3063\u305f\u3063\u3051\u2753\u2753\u300d<\/strong>\u3067\u304a\u5c4a\u3051\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u5185\u5bb9\u306f\u3068\u3044\u3046\u3068\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">SNS\u6642\u4ee3\u306b\u3088\u304f\u898b\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u300c\u3044\u3044\u306d\uff01\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u3068\u3044\u3048\u3070\u3001\u30d5\u30a7\u30a4\u30b9\u30d6\u30c3\u30af\u3067\u898b\u305f\u306e\u304c\u521d\u3081\u3066\u3067\u3059\u304c\u3001\u305d\u306e\u5f8c\u30db\u30f3\u30c8\u306b\u3053\u306e\u6a5f\u80fd\u306f\u3069\u3053\u3067\u3082\u898b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f<code>Laravel<\/code>\u3067\u3053\u306e\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u6a5f\u80fd\u3092\u3064\u304f\u3063\u3066\u307f\u307e\u3059\u3002<br \/>\n\u305c\u3072\u697d\u3057\u307f\u306a\u304c\u3089\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3566 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png\" alt=\"\" width=\"306\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1.png 306w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_1-287x300.png 287w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u751f\u307e\u308c\u3066\u521d\u3081\u3066\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d<br \/>\n\u3055\u308c\u305f\u3068\u304d\u306e\u8208\u596e\u306f\u4eca\u3067\u3082\u899a\u3048\u3066\u307e\u3059\ud83d\udc4d\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 7.x<\/p>\n<h1>\u524d\u63d0\u3068\u3057\u3066<\/h1>\n<p>\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u3059\u308b\u30c7\u30fc\u30bf\u306f\u306a\u3093\u3067\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3068\u4f5c\u6210\u3055\u308c\u308b<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u307e\u3060\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u306a\u3044\u65b9\u306f\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=4576\" target=\"_blank\" rel=\"noopener noreferrer\">Laravel6.x\u4ee5\u964d\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3092\u53c2\u8003\u306b\u3057\u3066\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u3084\u3063\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u306a\u304a\u3001\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7242\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_8.png\" alt=\"\" width=\"534\" height=\"465\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_8.png 534w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_8-300x261.png 300w\" sizes=\"auto, (max-width: 534px) 100vw, 534px\" \/><\/p>\n<h1>\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u3059\u308b<code>likes<\/code>\u30c6\u30fc\u30d6\u30eb\u3068\u305d\u306e\u30e2\u30c7\u30eb\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:model Like -m<\/strong><\/pre>\n<p>\u6b21\u306b\u3001\u4f5c\u6210\u3055\u308c\u305f\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30fb\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong><code>\/database\/migrations\/****_**_**_******_create_likes_table.php<\/code><\/strong><\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Support\\Facades\\Schema;\r\n\r\nclass CreateLikesTable extends Migration\r\n{\r\n    \/**\r\n     * Run the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function up()\r\n    {\r\n        Schema::create('likes', function (Blueprint $table) {\r\n            $table-&gt;id();\r\n            <strong>$table-&gt;string('model')-&gt;comment('\u30e2\u30c7\u30eb\u540d');<\/strong>\r\n<strong>            $table-&gt;integer('parent_id')-&gt;comment('\u30e2\u30c7\u30eb\u306eID');<\/strong>\r\n<strong>            $table-&gt;string('ip')-&gt;comment('IP\u30a2\u30c9\u30ec\u30b9');<\/strong>\r\n            $table-&gt;timestamps();\r\n        });\r\n    }\r\n\r\n    \/**\r\n     * Reverse the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function down()\r\n    {\r\n        Schema::dropIfExists('likes');\r\n    }\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u3053\u306e\u72b6\u614b\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7233\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_1.png\" alt=\"\" width=\"341\" height=\"274\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_1.png 341w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_1-300x241.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/p>\n<h1>likes\u30c6\u30fc\u30d6\u30eb\u3068\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u8a2d\u5b9a\u3059\u308b<\/h1>\n<p>\u6b21\u306b<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u304b\u3089<code>likes<\/code>\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30fc\u30bf\u3082\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u300c<strong>1\uff1a\u591a<\/strong>\u300d\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u3064\u304f\u3063\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\nclass User extends Authenticatable\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    \/\/ Relationship\r\n   <strong> public function likes() { \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n\r\n<strong>        return $this-&gt;hasMany(\\App\\Like::class, 'parent_id', 'id')<\/strong>\r\n<strong>            -&gt;where('model', self::class);<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n}<\/pre>\n<p>\u306a\u304a\u3001\u91cd\u8981\u306a\u306e\u306f<code>where()<\/code>\u306e\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u3053\u306e\u4f8b\u3067\u8a00\u3046\u3068<code>model<\/code>\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u300c<strong>App\\User<\/strong>\u300d\u3082\u306e\u3060\u3051\u53d6\u5f97\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u30eb\u30fc\u30c8\u3067\u3059\u3002<\/p>\n<pre><strong>Route::get('\/like', 'LikeController@index'); \/\/ \ud83d\udc48 \u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b<\/strong>\r\n<strong>Route::get('\/ajax\/like\/user_list', 'LikeController@user_list'); \/\/ \ud83d\udc48 \u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u53d6\u5f97<\/strong>\r\n<strong>Route::post('\/ajax\/like', 'LikeController@like'); \/\/ \ud83d\udc48 \u3044\u3044\u306d\uff01\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0<\/strong><\/pre>\n<p>1\u884c\u76ee\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b<code>URL<\/code>\u3067\u3001\u4e0b\u306e\uff12\u3064\u306f<code>Ajax<\/code>\u901a\u4fe1\u7528\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u6b21\u306b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308a\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:controller LikeController<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong><code>\/app\/Http\/Controllers\/LikeController.php<\/code><\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Illuminate\\Http\\Request;\r\n\r\nclass LikeController extends Controller\r\n{\r\n    <strong>public function index(Request $request) {\r\n\r\n        return view('like.index')-&gt;with('ip', $request-&gt;ip());\r\n\r\n    }\r\n\r\n    public function user_list() {\r\n\r\n        return $this-&gt;getUsers(); \/\/ \u5168\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\r\n\r\n    }\r\n\r\n    public function like(Request $request) {\r\n\r\n        $request-&gt;validate([\r\n            'user_id' =&gt; 'required|exists:users,id'\r\n        ]);\r\n\r\n        $result = false;\r\n        $model = \\App\\User::class;\r\n        $exists = \\App\\Like::where('model', $model)\r\n            -&gt;where('parent_id', $request-&gt;user_id)\r\n            -&gt;where('ip', $request-&gt;ip())\r\n            -&gt;exists();\r\n\r\n        if(!$exists) {\r\n\r\n            $like = new \\App\\Like();\r\n            $like-&gt;model = $model;\r\n            $like-&gt;parent_id = $request-&gt;user_id;\r\n            $like-&gt;ip = $request-&gt;ip();\r\n            $result = $like-&gt;save();\r\n\r\n        }\r\n\r\n        return [\r\n            'result' =&gt; $result,\r\n            'users' =&gt; $this-&gt;getUsers() \/\/ \u5168\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\r\n        ];\r\n\r\n    }\r\n\r\n    private function getUsers() {\r\n\r\n        return \\App\\User::with('likes')\r\n            -&gt;withCount('likes')\r\n            -&gt;get();\r\n\r\n    }<\/strong>\r\n}<\/pre>\n<p>\u305d\u308c\u3067\u306f\u3001\u4e2d\u8eab\u3092\u30e1\u30bd\u30c3\u30c9\u3054\u3068\u306b\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2>index()<\/h2>\n<p>\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3055\u308c\u308b\u3068\u304d\u306b\u5b9f\u884c\u3055\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\n\u306a\u304a\u3001\u30d3\u30e5\u30fc\u3067\u73fe\u5728\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u308b\u4eba\u306eIP\u30a2\u30c9\u30ec\u30b9\u304c\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>user_list()<\/h2>\n<p><code>Ajax<\/code>\u3067\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n<h2>like()<\/h2>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>getUsers()<\/h2>\n<p><code>LikeController<\/code>\u5185\u3067\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u6240\u304c2\u30f5\u6240\u3042\u308b\u306e\u3067\u3072\u3068\u3064\u306b\u307e\u3068\u3081\u307e\u3057\u305f\u3002\u306a\u304a\u3001<strong><code>private function<\/code>\u306a\u306e\u3067\u3053\u306e\u30af\u30e9\u30b9\u306e\u4e2d\u304b\u3089\u3057\u304b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/strong><\/p>\n<h1>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u6700\u5f8c\u306b\u30d3\u30e5\u30fc\u3067\u3059\u3002<\/p>\n<p><strong><code>\/resources\/views\/like\/index.blade.php<\/code><\/strong><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;link href=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.4.1\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div id=\"app\" class=\"container pt-4\"&gt;\r\n    &lt;h1 class=\"mb-3\"&gt;\u300c\u3044\u3044\u306d\uff01\u300d\u6a5f\u80fd\u306e\u30b5\u30f3\u30d7\u30eb&lt;\/h1&gt;\r\n    &lt;p class=\"bg-light p-3\"&gt;\u300c\u3044\u3044\u306d\uff01\u300d\u3067\u304d\u308b\u306e\u306f\u3001IP\u30a2\u30c9\u30ec\u30b9\u3054\u3068\u306b\uff11\u56de\u307e\u3067\u3067\u3059\u3002&lt;\/p&gt;\r\n    &lt;table class=\"table table-bordered\"&gt;\r\n        &lt;thead class=\"bg-info text-white\"&gt;\r\n            &lt;tr&gt;\r\n                &lt;th&gt;\u540d\u524d&lt;\/th&gt;\r\n                &lt;th class=\"text-nowrap\"&gt;\u3044\u3044\u306d\uff01\u306e\u56de\u6570&lt;\/th&gt;\r\n                &lt;th&gt;&lt;\/th&gt;\r\n            &lt;\/tr&gt;\r\n        &lt;\/thead&gt;\r\n        &lt;tbody&gt;\r\n            <strong>&lt;!-- \u30e6\u30fc\u30b6\u30fc\u30ea\u30b9\u30c8\u3092\u8868\u793a \u30fb\u30fb\u30fb \u2460 --&gt;\r\n            &lt;tr v-for=\"u in users\"&gt;\r\n                &lt;td class=\"w-100\" v-text=\"u.name\"&gt;&lt;\/td&gt;\r\n                &lt;td class=\"w-100\" v-text=\"u.likes_count\"&gt;&lt;\/td&gt;\r\n                &lt;td class=\"text-nowrap\"&gt;\r\n                    &lt;!-- \u3044\u3044\u306d\uff01\u3092\u5b9f\u884c\u3059\u308b\u30dc\u30bf\u30f3 \u30fb\u30fb\u30fb \u2461 --&gt;\r\n                    &lt;button\r\n                        type=\"button\"\r\n                        class=\"btn btn-info\"\r\n                        :disabled=\"hasMyLike(u.likes)\"\r\n                        @click=\"addLike(u.id)\"&gt;\u3044\u3044\u306d\uff01&lt;\/button&gt;\r\n                &lt;\/td&gt;\r\n            &lt;\/tr&gt;<\/strong>\r\n        &lt;\/tbody&gt;\r\n    &lt;\/table&gt;\r\n&lt;\/div&gt;\r\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/vue\/2.6.11\/vue.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/axios\/0.19.2\/axios.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script&gt;\r\n\r\n    new Vue({\r\n        el: '#app',\r\n        data: {\r\n            users: [],\r\n            ip: '{{ $ip }}'\r\n        },\r\n        methods: {\r\n            <strong>addLike(userId) { \/\/ \u3044\u3044\u306d\uff01\u3092\u8ffd\u52a0 \u30fb\u30fb\u30fb \u2460\r\n\r\n                const url = '\/ajax\/like';\r\n                const params = { user_id: userId };\r\n                axios.post(url, params)\r\n                    .then(response =&gt; {\r\n\r\n                        if(response.data.result === true) { \/\/ \u8ffd\u52a0\u306b\u6210\u529f\u3057\u305f\u3089\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\r\n\r\n                            this.users = response.data.users;\r\n\r\n                        }\r\n\r\n                    });\r\n\r\n            },\r\n            hasMyLike(likes) { \/\/ \u81ea\u5206\u306eIP\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af \u30fb\u30fb\u30fb \u2461\r\n\r\n                if(likes.length) {\r\n\r\n                    for(let like of likes) {\r\n\r\n                        if(like.ip === this.ip) {\r\n\r\n                            return true;\r\n\r\n                        }\r\n\r\n                    }\r\n\r\n                }\r\n\r\n                return false;\r\n\r\n            }\r\n        },<\/strong>\r\n        mounted() {\r\n\r\n            axios.get('\/ajax\/like\/user_list')\r\n                .then(response =&gt; {\r\n\r\n                    this.users = response.data;\r\n\r\n                });\r\n\r\n        }\r\n    });\r\n\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u306e\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p><strong>\u2460\u30e6\u30fc\u30b6\u30fc\u30ea\u30b9\u30c8\u3092\u8868\u793a<\/strong><\/p>\n<p><code>Vue.js<\/code>\u3092\u4f7f\u3063\u3066<code>Ajax<\/code>\u901a\u4fe1\u3067\u53d6\u5f97\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3092<code>v-for<\/code>\u3067\u30eb\u30fc\u30d7\u3055\u305b\u30011\u3064\u305a\u3064\u8868\u793a\u3057\u3066\u3044\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>\u2461\u3044\u3044\u306d\uff01\u3092\u5b9f\u884c\u3059\u308b\u30dc\u30bf\u30f3<\/strong><\/p>\n<p>\u30af\u30ea\u30c3\u30af\u3055\u308c\u308b\u3068\u3001<code>likes<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u304c\u8ffd\u52a0\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3055\u3089\u306b\u3001<code>:disabled<\/code>\u3092\u4f7f\u3063\u3066\u3059\u3067\u306b\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u30af\u30ea\u30c3\u30af\u304c\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u2462\u3044\u3044\u306d\uff01\u3092\u8ffd\u52a0<\/strong><\/p>\n<p>\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u30dc\u30bf\u30f3\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u3068\u304d\u306b\u5b9f\u884c\u3055\u308c\u308b\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f<code>Ajax<\/code>\u3067\u300c\u3044\u3044\u306d\uff01\u300d\u3059\u3079\u304d\u30e6\u30fc\u30b6\u30fcID\u3092\u9001\u4fe1\u3057\u3001\u3082\u3057<strong>\u65b0\u898f\u30c7\u30fc\u30bf\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3089<code>users<\/code>\u30c7\u30fc\u30bf\u3092\u65b0\u3057\u3044\u3082\u306e\u306b\u7f6e\u304d\u63db\u3048\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/strong><\/p>\n<p><strong>\u2463\u81ea\u5206\u306eIP\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af<\/strong><\/p>\n<p>\u3053\u3053\u306f\u3001\u2461\u3067\u8aac\u660e\u3057\u305f<code>:disabled<\/code>\u306e\u90e8\u5206\u3067\u4f7f\u308f\u308c\u308b<strong>\u300c\u3059\u3067\u306b\u300c\u3044\u3044\u306d\uff01\u300d\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u300d\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/strong><\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<br \/>\n<span style=\"font-size: 1rem;\">\u307e\u305a\u30d6\u30e9\u30a6\u30b6\u3067\u300c<strong>http:\/\/*****\/like<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7235\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_2.png\" alt=\"\" width=\"640\" height=\"460\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_2.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_2-300x216.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3067\u306f\u3001\u592a\u90ce\u3055\u3093\u3068\u6b21\u90ce\u3055\u3093\u306e\u300c\u3044\u3044\u306d\uff01\u300d\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7236\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_3.png\" alt=\"\" width=\"640\" height=\"455\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_3.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_3-300x213.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3059\u308b\u3068\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u306e\u56de\u6570\u304c\u5897\u3048\u3066\u3001\u30dc\u30bf\u30f3\u304c\u30af\u30ea\u30c3\u30af\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7237\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_4.png\" alt=\"\" width=\"576\" height=\"293\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_4.png 576w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_4-300x153.png 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/p>\n<p><strong>\u592a\u90ce\u3055\u3093\uff08\u30e6\u30fc\u30b6\u30fcID\uff1a 1\uff09<\/strong>\u3068<strong>\u6b21\u90ce\u3055\u3093\uff08\u30e6\u30fc\u30b6\u30fcID\uff1a 2\uff09<\/strong>\u306e\u30c7\u30fc\u30bf\u304c\u5b58\u5728\u3057\u3066\u3044\u3066\u3001IP\u30a2\u30c9\u30ec\u30b9\u3082\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u6b21\u306b\u3001\u592a\u90ce\u3055\u3093\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092\u624b\u52d5\u3067\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7238\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_5.png\" alt=\"\" width=\"575\" height=\"338\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_5.png 575w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_5-300x176.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u30d6\u30e9\u30a6\u30b6\u3092\u30ea\u30ed\u30fc\u30c9\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u592a\u90ce\u3055\u3093\u306e\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u3060\u3051\u30af\u30ea\u30c3\u30af\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7239\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_6.png\" alt=\"\" width=\"640\" height=\"455\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_6.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_6-300x213.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3067\u306f\u3053\u308c\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7240\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_7.png\" alt=\"\" width=\"640\" height=\"456\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_7.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/04\/laravel_like_7-300x214.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u306f\u3044\uff01<br \/>\n\u592a\u90ce\u3055\u3093\u306e\u300c<strong>\u3044\u3044\u306d\uff01<\/strong>\u300d\u304c2\u56de\u306b\u306a\u308a\u3001\u518d\u5ea6\u30dc\u30bf\u30f3\u306f\u30af\u30ea\u30c3\u30af\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<h1>\u6559\u6750\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u6559\u6750\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=7246&amp;tmstv=1777532241\" rel=\"nofollow\" id=\"download-link-7246\" data-redirect=\"false\" >\n\tLaravel\u3067\u300c\u3044\u3044\u306d\uff01\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\n\n<p>\u203b\u305f\u3060\u3057\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306f\u3054\u81ea\u8eab\u3067\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u3092\u4f7f\u3063\u3066\u300c\u3044\u3044\u306d\uff01\u300d\u6a5f\u80fd\u3092\u3064\u304f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u306a\u304a\u3001\u4ee5\u524d\u79c1\u306f<a href=\"https:\/\/github.com\/SUKOHI\/Evaluation\" target=\"_blank\" rel=\"noopener noreferrer\">Evaluation<\/a>\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u516c\u958b\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3082\u3057\u3088\u308a\u30b7\u30f3\u30d7\u30eb\u306b\u5b9f\u73fe\u3057\u305f\u3044\u65b9\u306f\u305d\u3061\u3089\u3082\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\uff08<code>Evaluationn<\/code>\u3067\u4f7f\u3048\u308b\u306e\u306f\u300c<strong>like<\/strong>\u300d\u300c<strong>dislike<\/strong>\u300d\u300c<strong>favorite<\/strong>\u300d\u300c<strong>remember<\/strong>\u300d\u306e\uff14\u3064\u3067\u3059\uff09<\/p>\n<p>\u3082\u3057\u304f\u306f\u3001\u4eca\u56de\u306e\u8a18\u4e8b\u3092\u3058\u3063\u304f\u308a\u52c9\u5f37\u3059\u308b\u306e\u3082\u3042\u308a\u304b\u3082\u3057\u308c\u307e\u305b\u3093\ud83d\udc4d<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6070 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_5.png\" alt=\"\" width=\"260\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_5.png 260w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_5-244x300.png 244w\" sizes=\"auto, (max-width: 260px) 100vw, 260px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u305d\u3046\u3044\u3048\u3070\u3001\u5f53\u6642\u306f\u30df\u30af\u30b7\u30a3<br \/>\n\u304c\u4eba\u6c17\u3067\u3057\u305f\u3088\u306d\uff08\u307e\u3060\u30a2\u30ab\u30a6\u30f3\u30c8\u3042\u308b\u304b\u306a\u2753\uff09\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4eca\u56de\u306f\u5c11\u3057\u524d\u306b\u516c\u958b\u3057\u305f\u300c\u3010Laravel\u3011\u30d5\u30a1\u30a4\u30eb\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6a5f\u80fd\u3092\u3064\u304f\u308b\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3068\u540c\u3058\u304f\u300c\u8a18\u4e8b\u306b\u3057\u3066\u306a\u304b\u3063\u305f\u3063\u3051\u2753\u2753\u300d\u3067\u304a\u5c4a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=7231\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel\u3067\u300c\u3044\u3044\u306d\uff01\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":7243,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7231","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7231"}],"version-history":[{"count":10,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7231\/revisions"}],"predecessor-version":[{"id":7253,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7231\/revisions\/7253"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/7243"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}