{"id":16389,"date":"2025-10-06T08:01:29","date_gmt":"2025-10-05T23:01:29","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=16389"},"modified":"2025-10-31T17:42:37","modified_gmt":"2025-10-31T08:42:37","slug":"switchbot%e3%81%ae%e6%8c%87%e3%83%ad%e3%83%9c%e3%83%83%e3%83%88%e3%82%92laravel%e3%81%8b%e3%82%89%e8%b5%b7%e5%8b%95%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=16389","title":{"rendered":"Switchbot\u306e\u6307\u30ed\u30dc\u30c3\u30c8\u3092Laravel\u304b\u3089\u8d77\u52d5\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-9-16 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"\u6307\u30ed\u30dc\u30c3\u30c8\u3092Switchbot API\u304b\u3089\u5b9f\u884c\u3059\u308b\" width=\"443\" height=\"788\" src=\"https:\/\/www.youtube.com\/embed\/leJlc6AG8UU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u3055\u3066\u3055\u3066\u3001\u524d\u56de\u6295\u7a3f\u3057\u305f\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=15667\" data-type=\"post\" data-id=\"15667\"><strong>\u65c5\u884c\u5148\u304b\u3089\u81ea\u5b85\u30d1\u30bd\u30b3\u30f3\u3092\u64cd\u4f5c\u3059\u308b\u5b8c\u5168\u653b\u7565\uff01<\/strong><\/a>\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u306e\u904e\u7a0b\u30671\u3064\u306e\u3053\u3068\u3092\u77e5\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Switchbot\u306fAPI\u304c\u3042\u308b\uff08\u3064\u307e\u308a\u3001\u30a6\u30a7\u30d6\u304b\u3089<strong>\u6307\u30ed\u30dc\u30c3\u30c8\u3092<\/strong>\u52d5\u304b\u305b\u308b\uff09<\/strong><\/p>\n\n\n\n<p>\u3063\u3066\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u6b63\u76f4\u306a\u3068\u3053\u308d\u3001\u524d\u56de\u306f\u500b\u4eba\u7684\u306b\u30ea\u30e2\u30fc\u30c8\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u4f7f\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3082\u3057\u4f1a\u793e\u306a\u3069\u30b0\u30eb\u30fc\u30d7\u3067\u4f7f\u3046\u5834\u5408\u306f\u3001\u305f\u3068\u3048\u3070\u30ea\u30e2\u30fc\u30c8\u3067\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A\u3055\u3093\u306f1\u756a\u76ee\u306e\u30d1\u30bd\u30b3\u30f3\u3092\u4f7f\u3048\u308b<\/li>\n\n\n\n<li>B\u3055\u3093\u306f2\u756a\u76ee\u30683\u756a\u76ee<\/li>\n\n\n\n<li>C\u3055\u3093\u306f\u5168\u90e8\u4f7f\u3048\u308b<\/li>\n<\/ul>\n\n\n\n<p>\u3068\u3044\u3063\u305f\u5177\u5408\u306b\u6a29\u9650\u3092\u4e0e\u3048\u308b\u3088\u3046\u306a\u4f7f\u3044\u65b9\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3057\u304b\u3057\u3001\u30a2\u30d7\u30ea\u304b\u3089\u8d77\u52d5\u3059\u308b\u5834\u5408\u306f\u6a29\u9650\u304c1\u4eba\u3060\u3051\u306b\u3042\u308b\u72b6\u6cc1\u3002<\/p>\n\n\n\n<p>\u3059\u308b\u3068\u3001\u6bce\u56de\u300c<strong>\u25cf\u25cf\u3055\u3093\u3001\u3059\u3044\u307e\u305b\u3093\uff011\u756a\u76ee\u306e\u30d1\u30bd\u30b3\u30f3\u3092\u8d77\u52d5\u3057\u3066\u304f\u3060\u3055\u3044<\/strong>\ud83d\ude02\u300d\u307f\u305f\u3044\u306a\u9023\u7d61\u3092\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u4ed5\u4e8b\u4e0a\u3081\u3093\u3069\u304f\u3055\u3044\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u305d\u3053\u3067\uff01<\/p>\n\n\n\n<p>\u4eca\u56de\u306f\u5404\u30e6\u30fc\u30b6\u30fc\u306b\u6a29\u9650\u3092\u4e0e\u3048\u3066\u3001\u305d\u306e\u4eba\u305f\u3061\u304c\u30a6\u30a7\u30d6\u4e0a\u304b\u3089<code>Switchbot<\/code>\uff08\u6307\u30ed\u30dc\u30c3\u30c8\uff09\u3092\u8d77\u52d5\u3059\u308b\u65b9\u6cd5\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<p>\u3064\u307e\u308a\u3001\u3053\u306e\u8a18\u4e8b\u306f\u6b21\u306e\u3088\u3046\u306a\u4eba\u306e\u305f\u3081\u306b\u66f8\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f1a\u793e\uff08\u30b0\u30eb\u30fc\u30d7\uff09\u3067\u30ea\u30e2\u30fc\u30c8\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u3092\u4f7f\u3044\u305f\u3044<\/li>\n\n\n\n<li>Switchbot\u3092\u30a6\u30a7\u30d6\u4e0a\u304b\u3089\u4f7f\u3044\u305f\u3044<\/li>\n\n\n\n<li>\u7ba1\u7406\u8005\u304c\u6307\u30ed\u30dc\u30c3\u30c8\u306e\u6a29\u9650\u3092\u5909\u66f4\u3057\u305f\u3044<\/li>\n\n\n\n<li>\u51fa\u5148\u304b\u3089\u30b5\u30fc\u30d0\u30fc\u30eb\u30fc\u30e0\u306e\u7269\u7406\u30b9\u30a4\u30c3\u30c1\u3092\u5207\u308a\u66ff\u3048\u305f\u3044<\/li>\n\n\n\n<li>Laravel\u30a2\u30d7\u30ea\u3068\u7269\u7406\u30c7\u30d0\u30a4\u30b9\u3092\u9023\u52d5\u3055\u305b\u305f\u3044<\/li>\n\n\n\n<li>DIY\u3067\u30ea\u30e2\u30fc\u30c8\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u3092\u6574\u5099\u3057\u305f\u3044<\/li>\n\n\n\n<li>IoT\u306b\u8208\u5473\u304c\u3042\u308a\u3001\u7269\u7406\u7684\u306a\u30c7\u30d0\u30a4\u30b9\u3092Laravel\u3068\u9023\u643a\u3055\u305b\u3066\u307f\u305f\u3044<\/li>\n\n\n\n<li>\u5192\u982d\u306e\u52d5\u753b\u307f\u305f\u3044\u306a\u3053\u3068\u304c\u3084\u308a\u305f\u3044<\/li>\n<\/ul>\n\n\n\n<p>\u305c\u3072\u6700\u5f8c\u307e\u3067\u8aad\u3093\u3067\u304f\u3060\u3055\u3044\u306d\uff01<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"294\" height=\"320\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png\" alt=\"\" class=\"wp-image-9470\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png 294w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13-276x300.png 276w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/><\/figure><\/div>\n\n\n<p class=\"has-text-align-center\">\u300c\u30ef\u30fc\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u98df\u3079\u305f\u4e00\u9db4\u306e<br>\u3072\u306a\u9ce5\u3001\u30ac\u30c3\u30c1\u3067\u3046\u307e\u304b\u3063\u305f\uff01\uff01\uff01\u300d<\/p>\n\n\n\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong>&nbsp;Laravel 12.x\u3001Vue 3\uff08Inertia\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u3054\u6ce8\u610f\u70b9<\/h2>\n\n\n\n<p>\u4eca\u56de\u306f\u300c<code>Switchbot<\/code>\u3092\u30a6\u30a7\u30d6\u304b\u3089\u64cd\u4f5c\u3059\u308b\u300d\u6a5f\u80fd\u306b\u30d5\u30a9\u30fc\u30ab\u30b9\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u901a\u5e38\u306e\u958b\u767a\u3067\u3064\u304f\u308b\u3079\u304d<code>role<\/code>\u3084\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u3064\u304b\u3063\u305f\u30a2\u30af\u30bb\u30b9\u5236\u9650\u306f\u7701\u7565\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001API\u30ea\u30bd\u30fc\u30b9\u3067\u300c\u516c\u958b\u3057\u3066\u3082\u554f\u984c\u306a\u3044\u30c7\u30fc\u30bf\u300d\u3060\u3051\u3092\u30d5\u30ed\u30f3\u30c8\u306b\u6e21\u3059\u3079\u304d\u3067\u3059\u304c\u3001\u3053\u3053\u3082\u7701\u7565\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\ud83d\ude47<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8b\u524d\u6e96\u5099\u3092\u3059\u308b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Switchbot\u306e\u30c8\u30fc\u30af\u30f3\uff08\u30a2\u30af\u30bb\u30b9&amp;\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\uff09\u3092\u53d6\u5f97\u3059\u308b<\/h3>\n\n\n\n<p><code>Switchbot API<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3<\/li>\n\n\n\n<li>\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30c8\u30fc\u30af\u30f3<\/li>\n<\/ul>\n\n\n\n<p>\u306e2\u3064\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br>\u3053\u308c\u3089\u306f\u30a2\u30d7\u30ea\u304b\u3089\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u753b\u9762\u4e0b\u306b\u3042\u308b\u300c<strong>\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb &gt; \u8a2d\u5b9a<\/strong>\u300d\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"490\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-1.png\" alt=\"\" class=\"wp-image-16583\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-1.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-1-283x300.png 283w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u300c<strong>\u57fa\u672c\u30c7\u30fc\u30bf<\/strong>\u300d\u3092\u9078\u629e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"249\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-2.png\" alt=\"\" class=\"wp-image-16586\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-2.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-2-300x162.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u300c<strong>\u30a2\u30d7\u30ea\u30d0\u30fc\u30b8\u30e7\u30f3<\/strong>\u300d\u3068\u3044\u3046\u9805\u76ee\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001<strong>\u3053\u3053\u309210\u56de\u3050\u3089\u3044\u30bf\u30c3\u30c1\u3057\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"403\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-3.png\" alt=\"\" class=\"wp-image-16587\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-3.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-3-300x262.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u3059\u308b\u3068\u3001\u958b\u767a\u8005\u5411\u3051\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"474\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-4.png\" alt=\"\" class=\"wp-image-16600\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-4.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-4-292x300.png 292w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u305d\u3057\u3066\u3001\u3053\u3053\u3092\u9078\u629e\u3059\u308b\u30682\u3064\u306e\u30c8\u30fc\u30af\u30f3\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"426\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-5.png\" alt=\"\" class=\"wp-image-16591\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-5.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-5-300x277.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u305d\u308c\u305e\u308c\u3001\u53f3\u5074\u306b\u3042\u308b\u30b3\u30d4\u30fc\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066<code>Google Keep<\/code>\u306a\u3069\u306b\u8cbc\u308a\u4ed8\u3051\u3066\u30d1\u30bd\u30b3\u30f3\u306e\u65b9\u3078\u79fb\u52d5\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u30c8\u30fc\u30af\u30f3\u304c\u53d6\u5f97\u3067\u304d\u305f\u3089\u3001<code>Laravel<\/code>\u306e<code>.env<\/code>\u30d5\u30a1\u30a4\u30eb\u306b\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>SWITCHBOT_ACCESS_TOKEN=********************************************<br>SWITCHBOT_SECRET_TOKEN=***************************<\/strong><\/pre>\n\n\n\n<p>\u307e\u305f\u3001<code>Laravel<\/code>\u304c\u30b3\u30f3\u30d5\u30a3\u30b0\u304b\u3089\u3053\u308c\u3089\u306e\u30c8\u30fc\u30af\u30f3\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p><strong>config\/services.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php<br><br>return [<br><br>    \/\/ \u7701\u7565<br><br>    <strong>'switchbot' =&gt; [<br>        'access_token' =&gt; env('SWITCHBOT_ACCESS_TOKEN'),<br>        'secret_token' =&gt; env('SWITCHBOT_SECRET_TOKEN'),<br>    ],<\/strong><br><br>];<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Switchbot\u306e\u30c7\u30d0\u30a4\u30b9ID\u3092\u53d6\u5f97\u3059\u308b<\/h3>\n\n\n\n<p>\u6b21\u306b\u300c\u30c7\u30d0\u30a4\u30b9ID\u300d\u3068\u547c\u3070\u308c\u308b\u3001\u52d5\u304b\u3057\u305f\u3044\u6a5f\u68b0\u306e\u30e6\u30cb\u30fc\u30afID\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3057\u3066\u3001\u30c7\u30d0\u30a4\u30b9ID\u306fAPI\u3092\u901a\u3057\u3066\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u304c\u3001<strong>\u3053\u3061\u3089\u3082\u30a2\u30d7\u30ea\u304b\u3089\u624b\u3063\u53d6\u308a\u65e9\u304f\u53d6\u5f97\u3067\u304d\u308b<\/strong>\u306e\u3067\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30a2\u30d7\u30ea\u306b\u6307\u30ed\u30dc\u30c3\u30c8\u3092\u767b\u9332\u3059\u308b\u3068\u3001\u30db\u30fc\u30e0\u753b\u9762\u306b\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001\u8a72\u5f53\u3059\u308b\u3082\u306e\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"218\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-6.png\" alt=\"\" class=\"wp-image-16608\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-6.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-6-300x142.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u300c\u30c7\u30d0\u30a4\u30b9\u60c5\u5831\u300d\u3092\u9078\u629e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"283\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-7.png\" alt=\"\" class=\"wp-image-16610\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-7.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-7-300x184.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u3059\u308b\u3068\u3001<code>BLE MAC<\/code>\u3068\u3044\u3046\u9805\u76ee\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3053\u308c\u304c\u300c<strong>\u30c7\u30d0\u30a4\u30b9ID<\/strong>\u300d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"has-small-font-size\">\u203b\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3067\u4f7f\u3046\u5834\u5408\u306f\u30b3\u30ed\u30f3\u3092\u9664\u53bb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"154\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-8.png\" alt=\"\" class=\"wp-image-16611\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-8.png 462w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-8-300x100.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p>\u3053\u306eID\u306f\u5f8c\u3067\u4f7f\u3046\u306e\u3067\u3001\u63a7\u3048\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u3092\u3064\u304f\u308b<\/h3>\n\n\n\n<p>\u3059\u3067\u306b<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u306f\u5b58\u5728\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u5148\u306b\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>php artisan make:seed UserSeeder<\/strong><\/pre>\n\n\n\n<p>\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;?php<br><br>namespace Database\\Seeders;<br><br>use App\\Models\\User;<br>use Illuminate\\Database\\Console\\Seeds\\WithoutModelEvents;<br>use Illuminate\\Database\\Seeder;<br><br>class UserSeeder extends Seeder<br>{<br>    \/**<br>     * Run the database seeds.<br>     *\/<br>    public function run(): void<br>    {<br>        $userItems = [<br>            ['email' =&gt; 'taro.yamada@example.com', 'name' =&gt; '\u5c71\u7530\u592a\u90ce'],<br>            ['email' =&gt; 'jiro.sato@example.com', 'name' =&gt; '\u4f50\u85e4\u4e8c\u90ce'],<br>            ['email' =&gt; 'saburo.tanaka@example.com', 'name' =&gt; '\u7530\u4e2d\u4e09\u90ce'],<br>        ];<br><br>        foreach ($userItems as $userItem) {<br><br>            $user = new User();<br>            $user-&gt;email = $userItem['email'];<br>            $user-&gt;name = $userItem['name'];<br>            $user-&gt;password = bcrypt('xxxxxxxx');<br>            $user-&gt;save();<br><br>        }<br>    }<br>}<\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">DB\u307e\u308f\u308a\u3092\u3064\u304f\u308b<\/h2>\n\n\n\n<p>\u6b21\u306b\u3001\u30e2\u30c7\u30eb\u3068\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308a\u307e\u3059\u3002<br>\u5fc5\u8981\u306a\u306e\u306f\u3001\u4ee5\u4e0b2\u3064\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>user_switchbot_permissions\uff1a\u30e6\u30fc\u30b6\u30fc\u306e\u30a2\u30af\u30bb\u30b9\u6a29\u9650\u3092\u7ba1\u7406<\/li>\n\n\n\n<li>switchbot_devices\uff1aSwitchbot\u30c7\u30d0\u30a4\u30b9\uff08\u6307\u30ed\u30dc\u30c3\u30c8\u3068\u304b\uff09\u306e\u7ba1\u7406<\/li>\n<\/ul>\n\n\n\n<p>\u3067\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c92\u3064\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>php artisan make:model SwitchBotDevice -ms<\/strong><br><strong>php artisan make:model UserSwitchbotPermision -ms<\/strong><\/pre>\n\n\n\n<p>\u3059\u308b\u3068\u3001\u5408\u8a086\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<br>\u305d\u308c\u305e\u308c\u5fc5\u8981\u306a\u3082\u306e\u3092\u5909\u66f4\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30e2\u30c7\u30eb<\/h3>\n\n\n\n<p><strong>app\/Models\/SwitchBotDevice.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;?php<br><br>namespace App\\Models;<br><br>use Illuminate\\Database\\Eloquent\\Model;<br><br>class SwitchBotDevice extends Model<br>{<br>    public function turnOnSwitchBotDevice() \/\/ SwitchBot\u30c7\u30d0\u30a4\u30b9\u3092\u30aa\u30f3\u306b\u3059\u308b<br>    {<br>        $deviceId = str_replace(':', '', $this-&gt;unique_id); \/\/ \u30b3\u30ed\u30f3\u3092\u9664\u53bb<br>        $token = config('services.switchbot.access_token');<br>        $secret = config('services.switchbot.secret_token');<br><br>        $nonce = $this-&gt;guidv4();<br>        $t = time() * 1000;<br>        $data = mb_convert_encoding($token . $t . $nonce, 'UTF-8');<br>        $sign = hash_hmac('sha256', $data, $secret, true);<br>        $sign = strtoupper(base64_encode($sign));<br><br>        $url = 'https:\/\/api.switch-bot.com\/v1.1\/devices\/'. $deviceId .'\/commands';<br>        $payload = [<br>            'command' =&gt; 'turnOn',<br>            'parameter' =&gt; 'default',<br>            'commandType' =&gt; 'command',<br>        ];<br>        $headers = [<br>            'Content-Type: application\/json; charset=utf8',<br>            'Authorization: '. $token,<br>            'sign: '. $sign,<br>            'nonce: '. $nonce,<br>            't: '. $t,<br>        ];<br><br>        $ch = curl_init($url);<br>        curl_setopt($ch, CURLOPT_POST, true);<br>        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);<br>        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));<br>        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br><br>        $response = curl_exec($ch);<br>        curl_close($ch);<br><br>        echo $response;<br>    }<br><br>    private function guidv4($data = null)<br>    {<br>        $data = $data ?? random_bytes(16);<br>        assert(strlen($data) == 16);<br>        $data[6] = chr(ord($data[6]) &amp; 0x0f | 0x40);<br>        $data[8] = chr(ord($data[8]) &amp; 0x3f | 0x80);<br><br>        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));<br>    }<br>}<\/strong><\/pre>\n\n\n\n<p><strong>app\/Models\/UserSwitchbotPermission.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;?php<br><br>namespace App\\Models;<br><br>use Illuminate\\Database\\Eloquent\\Model;<br><br>class UserSwitchbotPermission extends Model<br>{<br>    \/\/ Relationship<br>    public function device()<br>    {<br>        return $this-&gt;belongsTo(SwitchBotDevice::class, 'device_id', 'id');<br>    }<br>}<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Seeder<\/h3>\n\n\n\n<p><strong>database\/seeders\/UserSwitchbotPermissionSeeder.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>&lt;?php<br><br>namespace Database\\Seeders;<br><br>use App\\Models\\SwitchBotDevice;<br>use App\\Models\\User;<br>use App\\Models\\UserSwitchbotPermission;<br>use Illuminate\\Database\\Console\\Seeds\\WithoutModelEvents;<br>use Illuminate\\Database\\Seeder;<br><br>class UserSwitchbotPermissionSeeder extends Seeder<br>{<br>    <em>\/**<br>     * Run the database seeds.<br>     *\/<br>    <\/em>public function run(): void<br>    {<br>        $users = User::<em>get<\/em>();<br>        $switchbotDevices = SwitchBotDevice::<em>get<\/em>();<br><br>        foreach ($users as $user) {<br><br>            $permission = new UserSwitchbotPermission();<br>            $permission-&gt;user_id = $user-&gt;id;<br>            $permission-&gt;device_id = $switchbotDevices-&gt;random()-&gt;id;<br>            $permission-&gt;save();<br><br>        }<br>    }<br>}<\/strong><\/pre>\n\n\n\n<p><strong>database\/seeders\/SwitchBotDeviceSeeder.php<\/strong><\/p>\n\n\n\n<p>\u3053\u3053\u3067\u5148\u307b\u3069\u53d6\u5f97\u3057\u305f\u300c<strong>\u30c7\u30d0\u30a4\u30b9ID<\/strong>\u300d\u3092\u3064\u304b\u3044\u307e\u3059\uff08unique_id\u306b\u30bb\u30c3\u30c8\u3057\u307e\u3059\uff09<br>\u30b3\u30fc\u30c9\u5185\u306b\u3042\u308b<code>XX:XX:XX:XX:XX:XX<\/code>\u306e\u90e8\u5206\u3092\u3001\u3054\u81ea\u8eab\u306e\u30c7\u30d0\u30a4\u30b9ID\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>&lt;?php<br><br>namespace Database\\Seeders;<br><br>use App\\Models\\SwitchBotDevice;<br>use Illuminate\\Database\\Console\\Seeds\\WithoutModelEvents;<br>use Illuminate\\Database\\Seeder;<br><br>class SwitchBotDeviceSeeder extends Seeder<br>{<br>    <em>\/**<br>     * Run the database seeds.<br>     *\/<br>    <\/em>public function run(): void<br>    {<br>        $devices = [<br>            ['name' =&gt; '\u6307\u30ed\u30dc\u30c3\u30c81', 'unique_id' =&gt; 'XX:XX:XX:XX:XX:XX'],<br>            ['name' =&gt; '\u6307\u30ed\u30dc\u30c3\u30c82', 'unique_id' =&gt; <strong>'XX:XX:XX:XX:XX:XX'<\/strong>],<br>            ['name' =&gt; '\u6307\u30ed\u30dc\u30c3\u30c83', 'unique_id' =&gt; <strong>'XX:XX:XX:XX:XX:XX'<\/strong>],<br>        ];<br><br>        foreach ($devices as $device) {<br><br>            $switchBotDevice = new SwitchBotDevice();<br>            $switchBotDevice-&gt;name = $device['name'];<br>            $switchBotDevice-&gt;unique_id = $device['unique_id'];<br>            $switchBotDevice-&gt;save();<br><br>        }<br>    }<br>}<\/strong><\/pre>\n\n\n\n<p class=\"has-small-font-size\">\u203b<code>XX:XX:XX:XX:XX:XX<\/code>\u306e\u90e8\u5206\u306f\u91cd\u8907\u3057\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\uff08\u610f\u5473\u304c\u306a\u3044\u306e\u3067\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<\/h3>\n\n\n\n<p><strong>database\/migrations\/****_**_**_******_create_user_switchbot_permissions_table.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>&lt;?php<br><br>use Illuminate\\Database\\Migrations\\Migration;<br>use Illuminate\\Database\\Schema\\Blueprint;<br>use Illuminate\\Support\\Facades\\Schema;<br><br>return new class extends Migration<br>{<br>    \/**<br>     * Run the migrations.<br>     *\/<br>    public function up(): void<br>    {<br>        Schema::create('user_switchbot_permissions', function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;unsignedBigInteger('user_id');<br>            $table-&gt;unsignedBigInteger('device_id');<br>            $table-&gt;timestamps();<br><br>            $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');<br>            $table-&gt;foreign('device_id')-&gt;references('id')-&gt;on('switch_bot_devices');<br>        });<br>    }<br><br>    \/**<br>     * Reverse the migrations.<br>     *\/<br>    public function down(): void<br>    {<br>        Schema::dropIfExists('user_switchbot_permissions');<br>    }<br>};<\/strong><\/pre>\n\n\n\n<p><strong>database\/migrations\/****_**_**_******_create_switch_bot_devices_table.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>&lt;?php<br><br>use Illuminate\\Database\\Migrations\\Migration;<br>use Illuminate\\Database\\Schema\\Blueprint;<br>use Illuminate\\Support\\Facades\\Schema;<br><br>return new class extends Migration<br>{<br>    <em>\/**<br>     * Run the migrations.<br>     *\/<br>    <\/em>public function up(): void<br>    {<br>        Schema::create('switch_bot_devices', function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string('name');<br>            $table-&gt;string('unique_id')-&gt;unique();<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    <em>\/**<br>     * Reverse the migrations.<br>     *\/<br>    <\/em>public function down(): void<br>    {<br>        Schema::dropIfExists('switch_bot_devices');<br>    }<br>};<\/strong><\/pre>\n\n\n\n<p>\u3067\u306f\u3001\u3053\u306e\u72b6\u614b\u3067DB\u3092\u521d\u671f\u5316\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n\n\n\n<p>\u5b9f\u969b\u306e\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"408\" height=\"263\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-9.png\" alt=\"\" class=\"wp-image-16631\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-9.png 408w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-9-300x193.png 300w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full image-border-3\"><img loading=\"lazy\" decoding=\"async\" width=\"367\" height=\"263\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-10.png\" alt=\"\" class=\"wp-image-16632\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-10.png 367w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-10-300x215.png 300w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u8ffd\u52a0\u3059\u308b<\/h2>\n\n\n\n<p><code>User<\/code>\u30e2\u30c7\u30eb\u306b\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br>\u8ffd\u52a0\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p><strong>app\/Models\/User.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;?php<br><br>namespace App\\Models;<br><br>\/* \u3053\u3053\u306f\u7701\u7565\u3057\u3066\u307e\u3059 *\/<br><br>class User extends Authenticatable<br>{<br>    \/* \u3053\u3053\u306f\u7701\u7565\u3057\u3066\u307e\u3059 *\/<br><br>    \/\/ Relationship<br>    public function switchbotPermissions()<br>    {<br>        return $this-&gt;hasMany(UserSwitchbotPermission::class, 'user_id', 'id');<br>    }<br>}<\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Switchbot\u306e\u6a29\u9650\u3092\u4ed8\u4e0e\uff0f\u89e3\u9664\u3059\u308b\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h3>\n\n\n\n<p>\u3067\u306f\u3001\u307e\u305a\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u3064\u304f\u308a\u307e\u3059\u3002<br>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>php artisan make:controller SwitchBotPermissionController<\/strong><\/pre>\n\n\n\n<p>\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>app\/Http\/Controllers\/SwitchBotPermissionController.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;?php<br><br>namespace App\\Http\\Controllers;<br><br>use App\\Models\\SwitchBotDevice;<br>use App\\Models\\User;<br>use App\\Models\\UserSwitchbotPermission;<br>use Illuminate\\Http\\Request;<br>use Inertia\\Inertia;<br><br>class SwitchBotPermissionController extends Controller<br>{<br>    public function index()<br>    {<br>        $users = User::query()<br>            -&gt;with('switchbotPermissions') \/\/ User\u30e2\u30c7\u30eb\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u540d<br>            -&gt;get();<br>        $switchbotDevices = SwitchBotDevice::get();<br><br>        return Inertia::render('SwitchBot\/Permission\/Index', [<br>            'users' =&gt; $users,<br>            'switchbotDevices' =&gt; $switchbotDevices,<br>        ]);<br>    }<br><br>    public function store(Request $request)<br>    {<br>        \/*** \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u7701\u7565\u3057\u3066\u3044\u307e\u3059 ***\/<br><br>        $result = false;<br>        $userId = $request-&gt;input('userId');<br>        $deviceId = $request-&gt;input('deviceId');<br>        $hasPermission = $request-&gt;input('hasPermission');<br><br>        if($hasPermission === true) { \/\/ \u6a29\u9650\u3092\u4ed8\u4e0e<br><br>            $permission = new UserSwitchbotPermission();<br>            $permission-&gt;user_id = $userId;<br>            $permission-&gt;device_id = $deviceId;<br>            $result = $permission-&gt;save();<br><br>        } else { \/\/ \u6a29\u9650\u3092\u89e3\u9664<br><br>            $result = UserSwitchbotPermission::where('user_id', $userId)<br>                -&gt;where('device_id', $deviceId)<br>                -&gt;first()<br>                -&gt;delete();<br><br>        }<br><br>        return ['result' =&gt; $result];<br>    }<br>}<\/strong><\/pre>\n\n\n\n<p>\u3053\u3061\u3089\u306f\u6a29\u9650\u3092\u4ed8\u4e0e\uff0f\u89e3\u9664\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p><strong>app\/Http\/Controllers\/SwitchBotDeviceController.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Models\\SwitchBotDevice;\nuse Illuminate\\Http\\Request;\nuse Inertia\\Inertia;\n\nclass SwitchBotDeviceController extends Controller\n{\n    public function index(Request $request)\n    {\n        $user = $request-&gt;user();\n        $user-&gt;load([\n            'switchbotPermissions' =&gt; function ($query) {\n\n                $query-&gt;orderBy('device_id'); \/\/ \u30c7\u30d0\u30a4\u30b9ID\u3067\u30bd\u30fc\u30c8\n\n            },\n            'switchbotPermissions.device',\n        ]);\n\n        return Inertia::render('SwitchBot\/Device\/Index', [\n            'switchbotPermissions' =&gt; $user-&gt;switchbotPermissions,\n        ]);\n    }\n\n    public function run(Request $request)\n    {\n        \/*** \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\uff08\u672c\u4eba\u78ba\u8a8d\uff09\u306f\u7701\u7565\u3057\u3066\u3044\u307e\u3059 ***\/\n\n        $deviceId = $request-&gt;input('deviceId');\n        $switchBotDevice = SwitchBotDevice::find($deviceId);\n\n        if(! is_null($switchBotDevice)) {\n\n            $switchBotDevice-&gt;turnOnSwitchBotDevice();\n\n        }\n    }\n}<\/strong><\/pre>\n\n\n\n<p>\u3053\u3061\u3089\u306f\u3001\u6307\u30ed\u30dc\u30c3\u30c8\u3092\u8d77\u52d5\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h3>\n\n\n\n<p>\u6b21\u306b<code>Vue 3<\/code>\u306e\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>resources\/js\/Pages\/SwitchBot\/Permission\/Index.vue<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;script setup lang=\"ts\"&gt;<br>import axios from 'axios';<br>import { ref } from 'vue';<br><br>interface User {<br>    id: number;<br>    name: string;<br>    email: string;<br>    switchbot_permissions: SwitchBotPermission[];<br>}<br>interface SwitchBotPermission {<br>    userId: number;<br>    device_id: number;<br>}<br>interface SwitchBotDevice {<br>    id: number;<br>    name: string;<br>    unique_id: string;<br>}<br>const props = defineProps&lt;{<br>    users: User[];<br>    switchbotDevices: SwitchBotDevice[];<br>}&gt;();<br><br>\/\/ \u6a29\u9650\u306e\u5909\u66f4<br>const isSaved = ref(false);<br>const onSwitchBotPermissionChange = (<br>    e: Event,<br>    userId: number,<br>    deviceId: number,<br>) =&gt; {<br>    const target = e.target as HTMLInputElement;<br>    const hasPermission = target.checked;<br><br>    \/\/ Ajax\u3067\u6a29\u9650\u5909\u66f4<br>    const url = route('switchbot.permission.store');<br>    const params = {<br>        userId,<br>        deviceId,<br>        hasPermission,<br>    };<br>    axios<br>        .post(url, params)<br>        .then(() =&gt; {<br>            isSaved.value = true;<br>            setTimeout(() =&gt; {<br>                isSaved.value = false;<br>            }, 2000);<br>        })<br>        .catch((error) =&gt; {<br>            console.error(error);<br>        });<br>};<br><br>\/\/ \u6a29\u9650\u304c\u3042\u308b\u304b\u3069\u3046\u304b<br>const hasPermission = (userId: number, deviceId: number): boolean =&gt; {<br>    const targetUser = props.users.find((user) =&gt; user.id === userId);<br>    if (targetUser) {<br>        const switchBotPermissions = targetUser.switchbot_permissions;<br>        const checkingDeviceIds = switchBotPermissions.map(<br>            (permission) =&gt; permission.device_id,<br>        );<br>        return checkingDeviceIds.includes(deviceId);<br>    }<br>    return false;<br>};<br>&lt;\/script&gt;<br><br>&lt;template&gt;<br>    &lt;div class=\"p-5\"&gt;<br>        &lt;div class=\"absolute bottom-5 left-5 text-green-600\" v-if=\"isSaved\"&gt;<br>            \u2705 \u4fdd\u5b58\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\uff01<br>        &lt;\/div&gt;<br>        &lt;h1 class=\"mb-3 font-bold\"&gt;SwitchBot\u30fb\u30e6\u30fc\u30b6\u30fc\u6a29\u9650&lt;\/h1&gt;<br>        &lt;div class=\"flex gap-3\"&gt;<br>            &lt;div<br>                v-for=\"user in users\"<br>                :key=\"user.id\"<br>                class=\"mb-4 w-64 rounded-lg bg-gray-100 p-4\"<br>            &gt;<br>                &lt;h2 class=\"mb-1 text-lg font-semibold\"&gt;{{ user.name }}&lt;\/h2&gt;<br>                &lt;p class=\"mb-6 text-sm text-gray-600\"&gt;{{ user.email }}&lt;\/p&gt;<br>                &lt;div<br>                    v-for=\"device in switchbotDevices\"<br>                    :key=\"device.id\"<br>                    class=\"mb-0.5\"<br>                &gt;<br>                    &lt;label class=\"inline-flex items-center\"&gt;<br>                        &lt;input<br>                            type=\"checkbox\"<br>                            class=\"text-blue00 form-checkbox h-5 w-5\"<br>                            :checked=\"hasPermission(user.id, device.id)\"<br>                            @change=\"<br>                                onSwitchBotPermissionChange(<br>                                    $event,<br>                                    user.id,<br>                                    device.id,<br>                                )<br>                            \"<br>                        \/&gt;<br>                        &lt;span class=\"ml-2 text-gray-700\"&gt;{{ device.name }}&lt;\/span&gt;<br>                    &lt;\/label&gt;<br>                &lt;\/div&gt;<br>            &lt;\/div&gt;<br>        &lt;\/div&gt;<br>    &lt;\/div&gt;<br>&lt;\/template&gt;<\/strong><\/pre>\n\n\n\n<p><strong>resources\/js\/Pages\/SwitchBot\/Device\/Index.vue<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>&lt;script setup lang=\"ts\"&gt;<br>import { ref } from 'vue';<br>import axios from 'axios';<br><br>interface SwitchBotPermission {<br>    id: number;<br>    user_id: number;<br>    device_id: number;<br>    device: {<br>        id: number;<br>        name: string;<br>        unique_id: string;<br>    };<br>}<br>defineProps&lt;{<br>    switchbotPermissions: SwitchBotPermission[];<br>}&gt;();<br><br>\/\/ Switchbot\u3092\u8d77\u52d5\u3059\u308b<br>const isRunning = ref(false);<br>const onSwitchBotButtonClick = (permission: SwitchBotPermission) =&gt; {<br>    const url = route('switchbot.device.run');<br>    const params = {<br>        deviceId: permission.device_id,<br>    };<br>    axios<br>        .post(url, params)<br>        .then(() =&gt; {<br>            isRunning.value = true;<br>            setTimeout(() =&gt; {<br>                isRunning.value = false;<br>            }, 2000);<br>        })<br>        .catch((error) =&gt; {<br>            console.error(error);<br>        });<br>};<br>&lt;\/script&gt;<br><br>&lt;template&gt;<br>    &lt;div class=\"p-5\"&gt;<br>        &lt;div class=\"absolute bottom-5 left-5 text-green-600\" v-if=\"isRunning\"&gt;<br>            \ud83c\udfc3 \u8d77\u52d5\u4e2d\u3067\u3059...<br>        &lt;\/div&gt;<br>        &lt;h1 class=\"mb-3 font-bold\"&gt;SwitchBot\u30fb\u30a6\u30a7\u30d6\u304b\u3089\u8d77\u52d5&lt;\/h1&gt;<br>        &lt;div class=\"flex gap-3\"&gt;<br>            &lt;div<br>                v-for=\"permission in switchbotPermissions\"<br>                :key=\"permission.id\"<br>                class=\"mb-4 w-56 rounded-lg bg-gray-100 p-4\"<br>            &gt;<br>                &lt;h2 class=\"mb-3 text-lg font-bold\"&gt;<br>                    {{ permission.device.name }}<br>                &lt;\/h2&gt;<br>                &lt;button<br>                    type=\"button\"<br>                    class=\"w-full rounded bg-blue-600 px-4 py-2 font-semibold text-white text-sm hover:bg-blue-600\"<br>                    @click=\"onSwitchBotButtonClick(permission)\"&gt;<br>                    \u8d77\u52d5\u3059\u308b<br>                &lt;\/button&gt;<br>            &lt;\/div&gt;<br>        &lt;\/div&gt;<br>    &lt;\/div&gt;<br>&lt;\/template&gt;<\/strong><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\uff01<br>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30d3\u30eb\u30c9\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><strong>npm run build<\/strong><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h2>\n\n\n\n<p>\u3067\u306f\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<br>\u307e\u305a\u306f\u6a29\u9650\u306e\u4ed8\u4e0e\uff0f\u89e3\u9664\u3059\u308b\u30da\u30fc\u30b8\u3067\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/******\/switchbot\/permission\">https:\/\/******\/switchbot\/permission<\/a>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"211\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-11.png\" alt=\"\" class=\"wp-image-16654\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-11.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-11-300x99.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>\u306f\u3044\uff01<br>\u5404\u30e6\u30fc\u30b6\u30fc\u306b\u30c7\u30d0\u30a4\u30b9\u306e<code>On\/Off<\/code>\u304c\u3067\u304d\u308b\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3067\u306f\u3001\u30c1\u30a7\u30c3\u30af\u304c\u5916\u308c\u3066\u3044\u308b\u3068\u3053\u308d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"284\" height=\"261\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2025\/10\/laravel-switchbot-12.png\" alt=\"\" class=\"wp-image-16656\"\/><\/figure>\n\n\n\n<p>\u306f\u3044\uff01<br>\u30c1\u30a7\u30c3\u30af\u304c\u5165\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3057\u304b\u3082\u30ea\u30ed\u30fc\u30c9\u3057\u3066\u3082\u30c1\u30a7\u30c3\u30af\u306f\u5909\u308f\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a<\/p>\n\n\n\n<p>\u3067\u306f\u3001\u6b21\u306f\u672c\u984c\u306e\u6307\u30ed\u30dc\u30c3\u30c8\u3092\u8d77\u52d5\u3059\u308b\u90e8\u5206\u3067\u3059\u3002<br>\u3053\u308c\u306f\u52d5\u753b\u3067\u3054\u89a7\u304f\u3060\u3055\u3044\uff01<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-9-16 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"\u6307\u30ed\u30dc\u30c3\u30c8\u3092Switchbot API\u304b\u3089\u5b9f\u884c\u3059\u308b\" width=\"443\" height=\"788\" src=\"https:\/\/www.youtube.com\/embed\/leJlc6AG8UU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u306f\u3044\uff01<br>\u30a6\u30a7\u30d6\u4e0a\u304b\u3089\u6307\u30ed\u30dc\u30c3\u30c8\u3092\u8d77\u52d5\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3059\u3079\u3066\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h2>\n\n\n\n<p>\u4eca\u56de\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u3048\u3070\u3001\u30b0\u30eb\u30fc\u30d7\u5185\u3067\u30ea\u30e2\u30fc\u30c8\u30ef\u30fc\u30af\u3092\u52b9\u7387\u7684\u306b\u5b9f\u65bd\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3057\u3001\u51fa\u5f35\u306e\u969b\u3082\u3061\u3087\u3063\u3068\u3057\u305f\u8a2d\u5b9a\u3092\u3059\u308b\u3060\u3051\u3067\u5b8c\u4e86\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3082\u3057\u304a\u624b\u4f1d\u3044\u3067\u304d\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u304a\u6c17\u8efd\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>\u304a\u5f85\u3061\u3057\u3066\u307e\u3059\ud83d\ude0a\u2728<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u304a\u308f\u308a\u306b<\/h2>\n\n\n\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Switchbot<\/code>\u3092\u30a6\u30a7\u30d6\u4e0a\u304b\u3089\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u305d\u3082\u305d\u3082<code>Switchbot<\/code>\u306f\u30ac\u30b8\u30a7\u30c3\u30c8\u306a\u306e\u3067\u3001\u307e\u3055\u304bAPI\u3067\u69d8\u3005\u306a\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u306f\u601d\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3063\u3066\u3001\u30a2\u30a4\u30c7\u30a2\u6b21\u7b2c\u3067\u3057\u3063\u304b\u308a\u4ed5\u4e8b\u306b\u3082\u5fdc\u7528\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3088\u306d\u3002<\/p>\n\n\n\n<p>\u3082\u3057\u4eca\u5f8c\u300c\u3042\u30fc\u3001\u3053\u308c\u6307\u30ed\u30dc\u30c3\u30c8\u3064\u304b\u3048\u308b\u308f\u300d\u307f\u305f\u3044\u306a\u72b6\u6cc1\u306b\u306a\u3063\u305f\u3089\u3001\u307e\u305f\u5225\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305c\u3072\u304a\u697d\u3057\u307f\u306b\u3002<br>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"310\" height=\"320\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png\" alt=\"\" class=\"wp-image-3405\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png 310w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18-291x300.png 291w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/figure><\/div>\n\n\n<p class=\"has-text-align-center\">\u300c\u884c\u3063\u305f\u306e\u306f\u9999\u5ddd\u770c\u3067\u3059\u304c\u3001<br>\u5fb3\u5cf6\u30e9\u30fc\u30e1\u30f3\u30012\u56de\u884c\u304d\u307e\u3057\u305f\uff08\u7b11\uff09\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u524d\u56de\u6295\u7a3f\u3057\u305f\u300c\u65c5\u884c\u5148\u304b\u3089\u81ea\u5b85\u30d1\u30bd\u30b3\u30f3\u3092\u64cd\u4f5c\u3059\u308b\u5b8c\u5168\u653b\u7565\uff01\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u306e\u904e\u7a0b\u30671\u3064\u306e\u3053\u3068\u3092\u77e5\u308a\u307e\u3057\u305f\u3002 \u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb Swit &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=16389\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Switchbot\u306e\u6307\u30ed\u30dc\u30c3\u30c8\u3092Laravel\u304b\u3089\u8d77\u52d5\u3059\u308b\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":16690,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[262],"tags":[264],"class_list":["post-16389","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-262","tag-switchbot"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/16389","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=16389"}],"version-history":[{"count":300,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/16389\/revisions"}],"predecessor-version":[{"id":16714,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/16389\/revisions\/16714"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/16690"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}