{"id":2804,"date":"2018-12-10T04:09:24","date_gmt":"2018-12-09T19:09:24","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2804"},"modified":"2018-12-10T04:09:24","modified_gmt":"2018-12-09T19:09:24","slug":"%e5%8d%b1%e9%99%ba%ef%bc%81blade%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%83%87%e3%82%a3%e3%83%ac%e3%82%af%e3%83%86%e3%82%a3%e3%83%96%e3%81%a7%e6%b0%97%e3%82%92%e3%81%a4%e3%81%91%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2804","title":{"rendered":"\u5371\u967a\uff01Blade\u306e\u30ab\u30b9\u30bf\u30e0\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3067\u6c17\u3092\u3064\u3051\u308b\u3079\u304d\u3053\u3068"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Laravel\u306e\u5b88\u5099\u7bc4\u56f2\u304c\u5e83\u3044\u3053\u3068\u306f\u3053\u306e\u30d6\u30ed\u30b0\u3067\u3082\u3088\u304f\u8a18\u4e8b\u3067\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u3093\u306aLaravel\u306b\u3082\u3055\u3059\u304c\u306b\u6211\u3005\u304c\u5fc5\u8981\u3068\u3059\u308b\u3082\u306e\u5168\u3066\u3092\u521d\u671f\u72b6\u614b\u3067\u5099\u3048\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3068\u306f\u3044\u3063\u3066\u3082\u3001Laravel\u304c\u305d\u308c\u3067\u3082\u4eba\u6c17\u304c\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306a\u306e\u306f\u3001\u305d\u306e\u30d5\u30ec\u30ad\u30b7\u30d3\u30ea\u30c6\u30a3\u304c\u7406\u7531\u306b\u3042\u3052\u3089\u308c\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u8db3\u308a\u306a\u3044\u6a5f\u80fd\u3092\u72ec\u81ea\u306b\u62e1\u5f35\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\uff08\u3082\u3057\u304f\u306f\u3057\u3084\u3059\u3044\u3088\u3046\u306b\uff09\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3057\u3066\u4eca\u56de\u306e\u30c6\u30fc\u30de\u3001Blade\uff08\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3\uff09\u3082\u3053\u306e\u4f8b\u5916\u3067\u306f\u306a\u304f\u3001\u81ea\u5206\u81ea\u8eab\u304c\u307b\u3057\u3044\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u72ec\u81ea\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u3053\u306eBlade\u306e\u30ab\u30b9\u30bf\u30e0\u30fb\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3002<br \/>\n\u5b9f\u306f\u6c17\u3092\u3064\u3051\u3066\u304a\u304b\u306a\u3044\u3068\u601d\u308f\u306c\u4e0d\u5177\u5408\u306e\u539f\u56e0\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u4eca\u56de\u306f\u3069\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u4e0d\u5177\u5408\u304c\u767a\u751f\u3059\u308b\u539f\u56e0\u306b\u306a\u308b\u304b\u3001\u307e\u305f\u305d\u306e\u5bfe\u51e6\u6cd5\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2597 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png\" alt=\"\" width=\"275\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png 275w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2-236x300.png 236w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><\/p>\n<p>\u203b \u5b9f\u884c\u74b0\u5883\uff1a Laravel 5.7<\/p>\n<h1>Blade\u306e\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068\u306f<\/h1>\n<p>\u307e\u305a\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068\u306f\u3001Blade\u5185\u3067\u4f7f\u3048\u308b\u69d8\u3005\u306a\u6a5f\u80fd\u3092\u3082\u3063\u305f\u547d\u4ee4\u6587\u306e\u3053\u3068\u3067\u3001\u901a\u5e38\u306f\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3088\u304f\u4f7f\u308f\u308c\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<ul>\n<li>@section()<\/li>\n<li>@yield()<\/li>\n<li>@extends()<\/li>\n<\/ul>\n<p>\u306a\u3069\u306a\u3069\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u30ab\u30b9\u30bf\u30e0\u30fb\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306f\u3053\u306e\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u62e1\u5f35\u3057\u3001\u72ec\u81ea\u306e\u547d\u4ee4\u6587\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001<code>@datetime()<\/code>\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001\u521d\u671f\u72b6\u614b\u3067\u306fLaravel\u306b\u306f\u306a\u3044\u3082\u306e\u3067\u3059\u304c\u3001\u72ec\u81ea\u306b\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3067Blade\u5185\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u8a73\u3057\u3044\u30ab\u30b9\u30bf\u30e0\u30fb\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306e\u4f5c\u308a\u65b9\u306f<a href=\"https:\/\/blog.capilano-fw.com\/?p=405\">\u5fc5\u898b\uff01Laravel\uff085.6\uff09\u306eBlade\u3067\u3067\u304d\u308b\u3053\u3068\u300c\u307e\u3068\u3081\u300d<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u3069\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u4e0d\u5177\u5408\u304c\u767a\u751f\u3059\u308b\uff1f<\/h1>\n<p>\u5148\u306b\u7d50\u8ad6\u3092\u8a00\u3046\u3068\u3001<strong>\u5b9f\u884c\u306e\u5ea6\u306b\u30b3\u30f3\u30c6\u30f3\u30c4\u5185\u5bb9\u304c\u5909\u66f4\u306b\u306a\u308b\u5834\u5408<\/strong>\u3067\u3059\u3002\uff08\u305f\u3060\u3057\u3001\u3053\u306e\u5834\u5408\u3067\u3082\u5168\u3066\u306e\u5834\u5408\u306b\u4e0d\u5177\u5408\u304c\u767a\u751f\u3059\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\uff09<\/p>\n<p><span style=\"font-size: 1rem;\">\u3067\u306f\u3001\u5b9f\u969b\u306b\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n<\/span><\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u5931\u6557\u3057\u305f\u3089\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre><strong>\/\/ app\/Providers\/AppServiceProvider.php\n<\/strong>\/\/ \u6ce8\u610f\uff1a \u4e0d\u5177\u5408\u304c\u3042\u308b\u4f8b\u3067\u3059\uff01\n\npublic function boot()\n{\n    <strong>Blade::directive('error', function($key) {<\/strong>\n\n<strong>        if(session()-&gt;has('errors')) {<\/strong>\n\n<strong>            $errors = session('errors');<\/strong>\n\n<strong>            if($errors-&gt;has($key)) {<\/strong>\n\n<strong>                return '&lt;div class=\"alert alert-danger\"&gt;'. $errors-&gt;first($key) .'&lt;\/div&gt;';<\/strong>\n\n<strong>            }<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>    });<\/strong>\n}<\/pre>\n<p>\u305d\u3057\u3066\u547c\u3073\u51fa\u3059\u5074\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>@error(name)<\/strong><\/pre>\n<p>\u30b3\u30fc\u30c9\u81ea\u4f53\u306b\u30a8\u30e9\u30fc\u306f\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3001\u4e00\u898b\u3059\u308b\u3068\u3046\u307e\u304f\u3044\u304d\u305d\u3046\u3067\u3059\u304c\u3001\u3053\u306e\u5834\u5408\u3042\u308b\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong>\u300c\u4f55\u3082\u8868\u793a\u3055\u308c\u306a\u3044\u3002\u3002\u3002\uff08\u3082\u3057\u304f\u306f\u30a8\u30e9\u30fc\u304c\u51fa\u7d9a\u3051\u308b\u3002\u3002\u3002\uff09\u300d<\/strong><\/p>\n<p>\u30b3\u30fc\u30c9\u306f\u5408\u3063\u3066\u3044\u308b\u306e\u306b\u306a\u305c\u3053\u306e\u3088\u3046\u306a\u73fe\u8c61\u304c\u8d77\u3053\u308b\u306e\u3067\u3057\u3087\u3046\u304b\uff1f\uff1f<\/p>\n<h1>\u539f\u56e0\u306f\u30ad\u30e3\u30c3\u30b7\u30e5<\/h1>\n<p>Blade\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3068\u3057\u3066\u3001\u3088\u308a\u9ad8\u901f\u306b\u8868\u793a\u3059\u308b\u305f\u3081\u4e00\u5ea6\u5b9f\u884c\u3057\u305f\u90e8\u5206\u3092\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3059\u308b\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u300d\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u308c\u306f\u4eca\u56de\u306e\u30ab\u30b9\u30bf\u30e0\u30fb\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3067\u3082\u4f8b\u5916\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001<strong>AppServiceProvider.php\u5185\u306b\u5b9a\u7fa9\u3057\u305f\u30b3\u30fc\u30c9\u304c\u6bce\u56de\u5b9f\u884c\u3055\u308c\u308b\u308f\u3051\u3067\u306a\u3044<\/strong>\u306e\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u3053\u308c\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4e2d\u8eab\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;html&gt;\n&lt;body&gt;\n    <strong>&lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u958b\u59cb --&gt;<\/strong>\n<strong>    @error(email)<\/strong>\n<strong>    &lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u7d42\u4e86 --&gt;<\/strong>\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p><code>storage\/framework\/views<\/code>\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u4f5c\u6210\u3055\u308c\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u3067\u3059\u3002<\/p>\n<pre>&lt;html&gt;\n&lt;body&gt;\n    <strong>&lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u958b\u59cb --&gt;<\/strong>\n    \n<strong>    &lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u7d42\u4e86 --&gt;<\/strong>\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p><code>@error<\/code>\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u304c\u3042\u3063\u305f\u5834\u6240\u306b\u306f\u306a\u306b\u3082\u30b3\u30fc\u30c9\u304c\u66f8\u304b\u308c\u3066\u3044\u307e\u305b\u3093\uff01<\/p>\n<p>\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u5148\u307b\u3069<strong>\u5b9a\u7fa9\u3057\u305f\u30b3\u30fc\u30c9\u306f\u4e00\u756a\u6700\u521d\u306e\u30a2\u30af\u30bb\u30b9\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u4f5c\u6210\u3055\u308c\u3001\u305d\u306e\u3042\u3068\u306f\u3053\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u524a\u9664\u3055\u308c\u308b\u307e\u3067\u305a\u3063\u3068\u540c\u3058\u5185\u5bb9\u3092\u8868\u793a\u3057\u7d9a\u3051\u308b\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u3059\u3002<\/strong>\u305d\u306e\u305f\u3081\u4f55\u3082\u8868\u793a\u3055\u308c\u306a\u3044\u3001\u3082\u3057\u304f\u306f\u30a8\u30e9\u30fc\u304c\u51fa\u7d9a\u3051\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u73fe\u8c61\u304c\u767a\u751f\u3057\u3066\u3044\u305f\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001\u3053\u306e\u73fe\u8c61\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<h1>\u4e0d\u5177\u5408\u3092\u56de\u907f\u3059\u308b\u65b9\u6cd5<\/h1>\n<p>\u3082\u3057\u30ab\u30b9\u30bf\u30e0\u30fb\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u554f\u984c\u3092\u56de\u907f\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u307e\u305a\u4ee5\u4e0b\u306e\uff12\u70b9\u306e\u65b9\u6cd5\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u4f5c\u6210\u3055\u308c\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3059\u308b<\/li>\n<li>\u30ad\u30e3\u30c3\u30b7\u30e5\u81ea\u4f53\u306bPHP\u30b3\u30fc\u30c9\u3092\u57cb\u3081\u8fbc\u3080<\/li>\n<\/ul>\n<p>\u305f\u3060\u3001\uff11\u756a\u76ee\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3059\u308b\u5834\u5408\u3001\u5b9f\u969b\u306b\u3069\u308c\u304c\u30bf\u30fc\u30b2\u30c3\u30c8\u3068\u306a\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u308f\u304b\u3089\u306a\u3044\u305f\u3081\u3001<code>php artisan view:clear<\/code>\u3067\u5168\u3066\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u3042\u307e\u308a\u73fe\u5b9f\u7684\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u56de\u907f\u7b56\u3068\u3057\u3066\u306f\uff12\u756a\u3081\u306e\u300c\u30ad\u30e3\u30c3\u30b7\u30e5\u81ea\u4f53\u306bPHP\u30b3\u30fc\u30c9\u3092\u57cb\u3081\u8fbc\u3080\u300d\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u6bce\u56de\u5b9f\u884c\u3059\u308b\u5ea6\u306b\u4eca\u306e\u6642\u9593\u3092\u8868\u793a\u3059\u308b<code>@now<\/code>\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u4f5c\u6210\u3057\u3066\u547c\u3073\u51fa\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>Blade::directive(<strong>'now'<\/strong>, function() {\n\n    <strong>return '&lt;?php echo now();  ?&gt;';<\/strong>\n\n});<\/pre>\n<p><code>return<\/code>\u3059\u308b\u5185\u5bb9\u306bPHP\u30b3\u30fc\u30c9\u304c\u57cb\u3081\u8fbc\u307e\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u305d\u3057\u3066\u6b21\u306e\u3088\u3046\u306b\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\n&lt;body&gt;\n    &lt;!-- \u6642\u9593\u8868\u793a\u958b\u59cb --&gt;\n    <strong>@now()<\/strong>\n    &lt;!-- \u6642\u9593\u8868\u793a\u7d42\u4e86 --&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>\u3067\u306f\u3001\u4f5c\u6210\u3055\u308c\u305f\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4e2d\u8eab\u3067\u3059\u3002<\/p>\n<pre>&lt;html&gt;\n&lt;body&gt;\n    &lt;!-- \u6642\u9593\u8868\u793a\u958b\u59cb --&gt;\n    <strong>&lt;?php echo now();  ?&gt;<\/strong>\n    &lt;!-- \u6642\u9593\u8868\u793a\u7d42\u4e86 --&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>\u4eca\u5ea6\u306f\u30b3\u30fc\u30c9\u304c\u3046\u307e\u304f\u30ad\u30e3\u30c3\u30b7\u30e5\u5185\u306b\u66f8\u304d\u8fbc\u307e\u308c\u307e\u3057\u305f\u3002<br \/>\n\u3057\u304b\u3082\u3001PHP\u30b3\u30fc\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3001\u6bce\u56de\u9055\u3063\u305f\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u8868\u73fe\u304c\u5c11\u3057\u5909\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u304c\u3001<strong>\u300cPHP\u3067PHP\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u300d<\/strong>\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3059\u3002<\/p>\n<h1>\u4e0d\u5177\u5408\u3092\u56de\u907f\u3059\u308b\u5b9f\u4f8b<\/h1>\n<p>\u3067\u306f\u3001\u56de\u907f\u65b9\u6cd5\u304c\u308f\u304b\u3063\u305f\u306e\u3067\u3001\u3053\u308c\u3092\u8e0f\u307e\u3048\u3066\u5148\u307b\u3069\u306e<code>@error<\/code>\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u5148\u307b\u3069\u3068\u540c\u3058\u3088\u3046\u306b\u30b3\u30fc\u30c9\u3092\u3059\u3079\u3066<code>return<\/code>\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n<pre><strong>\/\/ AppServiceProvider.php<\/strong>\n\/\/ \u3053\u308c\u306f\u3001\u304a\u3059\u3059\u3081\u3057\u306a\u3044\u30b3\u30fc\u30c9\u3067\u3059\uff01\n\nBlade::directive('error', function($key) {\n\n    <strong>return '<\/strong>\n\n<strong>    &lt;?php<\/strong>\n\n<strong>    if(session()-&gt;has(\"errors\")) {<\/strong>\n\n<strong>        $errors = session(\"errors\");<\/strong>\n\n<strong>        if($errors-&gt;has(\"'. $key .'\")) {<\/strong>\n\n<strong>            $message = $errors-&gt;first(\"'. $key .'\");<\/strong>\n<strong>            echo \"&lt;div class=\\\"alert alert-danger\\\"&gt;\". $message .\"&lt;\/div&gt;\";<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>    }<\/strong>\n\n<strong>    ?&gt;<\/strong>\n\n<strong>    ';<\/strong>\n\n});<\/pre>\n<p>\u3053\u306e\u5f62\u3067\u5b9f\u884c\u3059\u308b\u3068\u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308b\u305f\u3081\u3001\u3053\u3061\u3089\u304c\u601d\u3063\u3066\u3044\u308b\u3068\u304a\u308a\u306b\u52d5\u3044\u3066\u304f\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;html&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    <strong>&lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u958b\u59cb --&gt;<\/strong>\n    \n\n<strong>            &lt;?php<\/strong>\n\n<strong>            if(session()-&gt;has(\"errors\")) {<\/strong>\n\n<strong>                $errors = session(\"errors\");<\/strong>\n\n<strong>                if($errors-&gt;has(\"email\")) {<\/strong>\n\n<strong>                    $message = $errors-&gt;first(\"email\");<\/strong>\n<strong>                    echo \"&lt;div class=\\\"alert alert-danger\\\"&gt;\". $message .\"&lt;\/div&gt;\";<\/strong>\n\n<strong>                }<\/strong>\n\n<strong>            }<\/strong>\n\n<strong>            ?&gt;<\/strong>\n\n            \n<strong>    &lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u7d42\u4e86 --&gt;<\/strong>\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>\u305f\u3060\u3057\u3001\u6b8b\u5ff5\u306a\u304c\u3089\u3053\u306e\u3084\u308a\u65b9\u306f\u3042\u307e\u308a\u304a\u3059\u3059\u3081\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u306f\u5c11\u3057\u9577\u3044\u305f\u3081\u3001\u53ef\u8aad\u6027\u304c\u3068\u3066\u3082\u60aa\u304f\u4fdd\u5b88\u3057\u306b\u304f\u3044\u304b\u3089\u3067\u3059\u3002\u5148\u307b\u3069\u3082\u8a00\u3063\u305f\u3088\u3046\u306b\u300cPHP\u3067PHP\u30b3\u30fc\u30c9\u3092\u3064\u304f\u308b\u300d\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3053\u3093\u306a\u3053\u3068\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u203b \u3082\u3061\u308d\u3093\u3001\u30b3\u30fc\u30c9\u304c\uff11\u884c\u3067\u66f8\u3051\u308b\u3050\u3089\u3044\u77ed\u3044\u3082\u306e\u3067\u3057\u305f\u3089\u4f55\u3082\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3067\u306f\u3001\u30b3\u30fc\u30c9\u304c\u9577\u3044\u5834\u5408\u306b\u306f\u3069\u3046\u3059\u308b\u3079\u304d\u304b\u3068\u3044\u3046\u3068\u300c\u30b3\u30fc\u30c9\u306e\u5206\u5272\u300d\u3067\u3059\u3002<\/p>\n<p>\u7d50\u5c40\u3001<code>return<\/code>\u3059\u308b\u5185\u5bb9\u306b<code>&lt;?php ... ?&gt;<\/code>\u304c\u542b\u307e\u308c\u3066\u3044\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u304b\u3089\u3001\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306b\u5c02\u7528\u306e\u30e2\u30c7\u30eb\u3092\u547c\u3073\u51fa\u3059\u65b9\u5f0f\u3078\u5909\u3048\u308c\u3070\u3044\u3044\u306e\u3067\u3059\u3002\uff08\u3082\u3057\u304f\u306f\u72ec\u81ea\u306e\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3067\u3082\u3044\u3044\u3067\u3057\u3087\u3046\uff09<\/p>\n<pre>Blade::directive('error', function($key) {\n\n    <strong>return '&lt;?php \\App\\BladeDirective::error(\"'. $key .'\"); ?&gt;';<\/strong>\n\n});<\/pre>\n<p>\u3068\u3066\u3082\u30b3\u30fc\u30c9\u304c\u3059\u3063\u304d\u308a\u3057\u307e\u3057\u305f\u3002<br \/>\n\u306a\u304a\u3001\u3053\u306e\u5834\u5408\u306e\u5c02\u7528\u30e2\u30c7\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass BladeDirective extends Model\n{\n    <strong>static public function error($key) {<\/strong>\n\n<strong>        if(session()-&gt;has('errors')) {<\/strong>\n\n<strong>            $errors = session('errors');<\/strong>\n\n<strong>            if($errors-&gt;has($key)) {<\/strong>\n\n<strong>                echo '&lt;div class=\"alert alert-danger\"&gt;'. $errors-&gt;first($key) .'&lt;\/div&gt;';<\/strong>\n\n<strong>            }<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>    }<\/strong>\n}<\/pre>\n<p>\u3067\u306f\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;html&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u958b\u59cb --&gt;\n    <strong>&lt;?php \\App\\BladeDirective::error(\"email\"); ?&gt;<\/strong>\n    &lt;!-- \u30a8\u30e9\u30fc\u8868\u793a\u7d42\u4e86 --&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>PHP\u30b3\u30fc\u30c9\u304c\u57cb\u3081\u8fbc\u307e\u308c\u3001<code>BladeDirective::error()<\/code>\u304c\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u306e\u3082\u3046\u3072\u3068\u3064\u30e1\u30ea\u30c3\u30c8\u306e\uff11\u3064\u3068\u3057\u3066\u3001\u3082\u3057\u30a8\u30e9\u30fc\u8868\u793a\u306e\u5185\u5bb9\u3092\u5909\u3048\u305f\u3044\u5834\u5408\u3067\u3082\u3044\u3061\u3044\u3061<code>php artisan view:clear<\/code>\u3067\u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u524a\u9664\u3059\u308b\u5fc5\u8981\u306f\u306a\u304f\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u3088\u308a\u4fdd\u5b88\u304c\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u3044\u3064\u3082\u3068\u306f\u5c11\u3057\u9055\u3063\u305f\u8a18\u4e8b\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u306a\u304a\u3001\u5b9f\u306f\u4ee5\u524d\u304b\u3089\u3053\u306eBlade\u306e\u30ab\u30b9\u30bf\u30e0\u30fb\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306b\u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u306b\u3088\u308b\u554f\u984c\u304c\u5b58\u5728\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u6539\u5584\u306f\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u500b\u4eba\u7684\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u7b2c\uff13\u5f15\u6570\u306b\u3067\u3082<code>boolean<\/code>\u5024\u3092\u8a2d\u5b9a\u3067\u304d\u3066\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b\u304b\u3057\u306a\u3044\u304b\u3092\u5236\u5fa1\u3067\u304d\u308c\u3070\u3044\u3044\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u3042\u307e\u308a\u30ab\u30b9\u30bf\u30e0\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u81ea\u4f53\u3092\u4f7f\u3046\u983b\u5ea6\u306f\u591a\u304f\u306a\u3044\u3067\u3059\u3057\u3001Laravel\u958b\u767a\u9663\u3082\u305d\u3053\u307e\u3067\u91cd\u8981\u8996\u3057\u3066\u3044\u306a\u3044\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre>\/\/ \u3053\u308c\u306f\u79c1\u306e\u5e0c\u671b\u3059\u308b\u30b3\u30fc\u30c9\u306a\u306e\u3067\u3001\u5b9f\u969b\u306b\u306f\u52d5\u304d\u307e\u305b\u3093\uff01\n\nBlade::directive('error', function($key) {\n\n    \/\/ \u7701\u7565\n\n}, <strong>false<\/strong>);<\/pre>\n<p>\uff08\u6642\u9593\u304c\u3067\u304d\u305f\u3089\u30d7\u30eb\u30ea\u30af\u30a8\u30b9\u30c8\u3068\u304b\u3057\u3066\u307f\u3088\u3046\u304b\u306a\uff1f\uff1f\uff09<\/p>\n<p>\u3067\u306f\u3067\u306f\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2595 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/7-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Laravel\u306e\u5b88\u5099\u7bc4\u56f2\u304c\u5e83\u3044\u3053\u3068\u306f\u3053\u306e\u30d6\u30ed\u30b0\u3067\u3082\u3088\u304f\u8a18\u4e8b\u3067\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u3093\u306aLaravel\u306b\u3082\u3055\u3059\u304c\u306b\u6211\u3005\u304c\u5fc5\u8981\u3068\u3059\u308b\u3082\u306e\u5168\u3066\u3092\u521d\u671f\u72b6\u614b\u3067\u5099\u3048\u3066 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2804\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u5371\u967a\uff01Blade\u306e\u30ab\u30b9\u30bf\u30e0\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3067\u6c17\u3092\u3064\u3051\u308b\u3079\u304d\u3053\u3068&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2814,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[57,69],"class_list":["post-2804","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-blade","tag-69"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2804","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=2804"}],"version-history":[{"count":8,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2804\/revisions"}],"predecessor-version":[{"id":2813,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2804\/revisions\/2813"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2814"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}