{"id":161,"date":"2021-09-09T03:33:48","date_gmt":"2021-09-08T18:33:48","guid":{"rendered":"https:\/\/rugoh.co.jp\/blog\/?p=161"},"modified":"2021-10-02T01:07:31","modified_gmt":"2021-10-01T16:07:31","slug":"20210909","status":"publish","type":"post","link":"https:\/\/rugoh.co.jp\/blog\/2021\/09\/09\/20210909\/","title":{"rendered":"Laravel8 Mailable \u672c\u6587\u3092\u52d5\u7684\u306b\u30bb\u30c3\u30c8"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"750\" height=\"500\" src=\"https:\/\/rugoh.co.jp\/blog\/wp-content\/uploads\/2021\/09\/20210909.png\" alt=\"\" class=\"wp-image-179\" srcset=\"https:\/\/rugoh.co.jp\/blog\/wp-content\/uploads\/2021\/09\/20210909.png 750w, https:\/\/rugoh.co.jp\/blog\/wp-content\/uploads\/2021\/09\/20210909-300x200.png 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>Mailable\u4f7f\u3063\u305f\u30e1\u30fc\u30eb\u9001\u4fe1\u306e\u5834\u5408\u3001\u5fc5\u305ablade\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<p>Mail::to(&#8216;info@hoge.co.jp&#8217;)-&gt;send(Mailable\u30af\u30e9\u30b9\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9);<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5225\u9014Mailable\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3001<\/p>\n\n\n\n<p>\u305d\u306e\u4e2d\u3067\u30e1\u30fc\u30eb\u672c\u6587\u306b\u8a72\u5f53\u3059\u308bblade\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u6307\u5b9a\u3059\u308b\u3002<\/p>\n\n\n\n<p>Mailable\u3092\u4f7f\u3063\u305f\u30e1\u30fc\u30eb\u9001\u4fe1\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306fGoogle\u3067\u691c\u7d22\u3059\u308b\u3068\u305f\u304f\u3055\u3093\u51fa\u3066\u304f\u308b\u306e\u3067\u3053\u3053\u3067\u306f\u5272\u611b\u3059\u308b\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4eca\u56de\u3084\u308a\u305f\u3044\u3053\u3068\u306f\u3053\u3046\u3060\u3002<\/p>\n\n\n\n<p>\u3068\u3042\u308b\u30b7\u30b9\u30c6\u30e0\u3067\u306f\u3001\u30e1\u30fc\u30eb\u672c\u6587\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u7ba1\u7406\u3057\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p>\u66f4\u306b\u672c\u6587\u306f\u3001Smarty\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5f62\u5f0f\u3092\u63a1\u7528\u3057\u3066\u304a\u308a\u3001<\/p>\n\n\n\n<p>\u9001\u4fe1\u524d\u306b\u3001\u5fc5\u8981\u306a\u5909\u6570\u306b\u306f\u8a72\u5f53\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u306e\u8a72\u5f53\u3059\u308b\u30ab\u30e9\u30e0\u306e\u5024\u306b\u7f6e\u304d\u63db\u3048\u3066\u9001\u4fe1\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3053\u3046\u3044\u3046\u4ed5\u69d8\u306e\u30b7\u30b9\u30c6\u30e0\u306e\u4e00\u90e8\u3092Laravel\u306b\u7f6e\u304d\u63db\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u8272\u3005\u3068\u8a66\u3057\u305f\u3002<\/p>\n\n\n\n<ul><li>blade\u3058\u3083\u306a\u304fsmarty\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u672c\u6587\u3092\u69cb\u7bc9\u3067\u304d\u308b\u304b<\/li><li>Mailable\u3092\u4f7f\u308f\u306a\u3044\u3067\u30e1\u30fc\u30eb\u9001\u4fe1\u3057\u3066\u307f\u308b\u304b<\/li><\/ul>\n\n\n\n<p>\u7d50\u679c\u3001\u3046\u307e\u304f\u3044\u304b\u305ablade\u3092\u4f7f\u3063\u3066\u3084\u3063\u3066\u307f\u308b\u304c\u3001<\/p>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e0a\u306b\u7121\u6570\u306b\u3042\u308b\u30e1\u30fc\u30eb\u672c\u6587\u30c7\u30fc\u30bf\u3092\u5168\u3066blade\u30d5\u30a1\u30a4\u30eb\u306b\u5909\u63db\u3059\u308b\u306e\u306f\u52b9\u7387\u304c\u60aa\u3059\u304e\u308b\u3057<\/p>\n\n\n\n<p>\u3044\u3064\u3069\u3053\u3067\u8ab0\u304c\u672c\u6587\u3092\u5909\u3048\u308b\u304b\u308f\u304b\u3089\u306a\u3044\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u76f8\u5f53\u306a\u6642\u9593\u3092\u8cbb\u3084\u3057\u3001\u767a\u60f3\u304b\u3089\u3082\u306e\u3059\u3054\u304f\u7c21\u5358\u306a\u65b9\u6cd5\u3067\u89e3\u6c7a\u3057\u305f\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>email.blade.php\u3092\u4f5c\u6210\u3059\u308b<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>resources\/views\/emails\/email.blade.php<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>{{$context}}<\/code><\/pre><\/div>\n\n\n\n<p>\u5185\u5bb9\u306f\u3053\u308c\u3060\u3051\u3002<\/p>\n\n\n\n<p>\u3067\u3001context\u5909\u6570\u306b\u3001Smarty\u3067\u30d3\u30eb\u30c9\u3057\u305f\u672c\u6587\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3060\u3051<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>app\/Mail\/HogeMail.php<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>namespace App\\Mail;\n \nuse Illuminate\\Bus\\Queueable;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Mail\\Mailable;\nuse Illuminate\\Queue\\SerializesModels;\nuse SmartyBC;\n \nclass HogeMail extends Mailable\n{\n    use Queueable, SerializesModels;\n    public $data;\n \n    \/**\n     * Create a new message instance.\n     *\n     * @return void\n     *\/\n    public function __construct($data)\n    {\n        $this-&gt;data = $data;\n    }\n \n    \/**\n     * Build the message.\n     *\n     * @return $this\n     *\/\n    public function build()\n    {\n        $smarty = new SmartyBC();\n        \/\/ Smarty\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u7528\u306e\u7f6e\u304d\u63db\u3048\u5909\u6570\n        $replacement = [\n          &#39;hoge&#39; =&gt; &#39;hogehoge&#39;\n        ];\n        $smarty-&gt;assign($replacement);\n        $template = $smarty-&gt;fetch(&#39;string:&#39;.$source); \/\/ $source\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u4fdd\u5b58\u3055\u308c\u305f\u672c\u6587\n        return $this-&gt;from($this-&gt;data[&#39;email&#39;], $this-&gt;data[&#39;name&#39;])\n            -&gt;subject(&#39;\u4ef6\u540d&#39;)\n            -&gt;text(&#39;emails.email&#39;)\n            -&gt;with([&#39;context&#39; =&gt; $template]);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>blade\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5074\u306f\u3001\u5909\u6570\u4e00\u500b\u3060\u3051\u7528\u610f\u3057\u3066<\/p>\n\n\n\n<p>\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u304b\u3089\u30e1\u30fc\u30eb\u672c\u6587\u3092\u30b4\u30c3\u30bd\u30ea\u5909\u6570\u3067\u6e21\u3059\u3060\u3051\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u30e1\u30fc\u30eb\u672c\u6587\u306e\u6570\u3060\u3051blade\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u308b\u5fc5\u8981\u304c\u7121\u3044\u5834\u5408\u306f<\/p>\n\n\n\n<p>\u3053\u3093\u306a\u65b9\u6cd5\u3082\u30a2\u30ea\u3063\u3061\u3083\u30a2\u30ea\u306a\u306e\u304b\u306a\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mailable\u4f7f\u3063\u305f\u30e1\u30fc\u30eb\u9001\u4fe1\u306e\u5834\u5408\u3001\u5fc5\u305ablade\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308b\u3002 Mail::to(&#8216;i&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":179,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[20,23,19],"_links":{"self":[{"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":4,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":180,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions\/180"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/media\/179"}],"wp:attachment":[{"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rugoh.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}