{"id":2961,"date":"2018-11-07T09:00:04","date_gmt":"2018-11-07T00:00:04","guid":{"rendered":"https:\/\/alaki.co.jp\/blog\/?p=2961"},"modified":"2020-08-09T14:18:12","modified_gmt":"2020-08-09T05:18:12","slug":"laravel%e3%81%a8twig%e3%81%a7%e3%82%a2%e3%82%af%e3%83%86%e3%82%a3%e3%83%96%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e5%88%a4%e5%ae%9a%e3%82%92%e3%81%97%e3%82%88%e3%81%86%ef%bc%81","status":"publish","type":"post","link":"http:\/\/test.alaki.co.jp\/blog\/?p=2961","title":{"rendered":"Laravel\u3068Twig\u3067\u30a2\u30af\u30c6\u30a3\u30d6\u30da\u30fc\u30b8\u306e\u5224\u5b9a\u3092\u3057\u3088\u3046\uff01"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001Web\u30d7\u30ed\u30b0\u30e9\u30de\u306e\u7be0\u7530\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001PHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u300cLaravel 5.6\u300d\u3068\u300cTwig\u300d\u3092\u4f7f\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3001<br \/>\nTwig\u5185\u3067\u73fe\u5728URL\u306e\u5024\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n<!--more--><\/p>\n<h2>\u3069\u3046\u3044\u3046\u3068\u304d\u306b\u300c\u73fe\u5728\u306eURL\u300d\u304c\u5fc5\u8981\u306b\u306a\u308b\u304b<\/h2>\n<p>\u300c\u73fe\u5728\u306eURL\u300d\u304c\u5fc5\u8981\u306b\u306a\u308b\u5834\u9762\u3068\u3057\u3066\u306f\u3001\u8868\u793a\u3057\u3066\u3044\u308b\u30da\u30fc\u30b8\u306e\u30e1\u30cb\u30e5\u30fc\u3092\u30a2\u30af\u30c6\u30a3\u30d6\u8868\u793a\u3057\u305f\u3044\u3068\u304d\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u305d\u3046\u3044\u3063\u305f\u3068\u304d\u306b\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5074\u306ePHP\u3067\u300c\u73fe\u5728\u306eURL\u300d\u3092\u53d6\u5f97\u3057\u3066\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5074\u306b\u9001\u308b\u3068\u3044\u3046\u4ed5\u7d44\u307f\u306f\u3001\u5168\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u5f71\u97ff\u3059\u308b\u306e\u3067\u5b9f\u88c5\u306f\u73fe\u5b9f\u7684\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u30da\u30fc\u30b8\u306e\u69cb\u6210\u4e0a\u5fc5\u8981\u3068\u306a\u308b\u30e1\u30cb\u30e5\u30fc\u90e8\u5206\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u300c\u73fe\u5728\u306eURL\u300d\u304c\u53d6\u5f97\u3067\u304d\u308c\u3070\u3001\u5168\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u624b\u3092\u52a0\u3048\u308b\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30d9\u30fc\u30b9\u3068\u306a\u308b\u30b3\u30fc\u30c9\u3092\u7528\u610f\u3059\u308b<\/h2>\n<p>\u30d9\u30fc\u30b9\u3068\u306a\u308b\u7c21\u5358\u306aLaravel\u306e\u30b3\u30fc\u30c9\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<h3>\u307e\u305a\u306f\u3001\u7c21\u5358\u306a\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u6210<\/h3>\n<p>\u300cartisan\u300d\u30b3\u30de\u30f3\u30c9\u3092\u5229\u7528\u3057\u3066\u3001\u300cItemController\u300d\u3068\u300cMemberController\u300d\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \" >$ php artisan make:controller ItemController\r\n$ php artisan make:controller MemberController\r\n  <\/pre>\n<p> \u300cItemController\u300d\u3068\u300cMemberController\u300d\u306b\u300cindex\u300d\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:php decode:true \" >class ItemController extends Controller\r\n{\r\n    public function index() {\r\n        return view('Item.index');\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"lang:php decode:true \" >class MemberController extends Controller\r\n{\r\n    public function index() {\r\n        return view('Member.index');\r\n    }\r\n}<\/pre>\n<p> \u8aad\u307f\u8fbc\u3080Twig\u30d5\u30a1\u30a4\u30eb\u306f\u300cviews\/Item\/index.twig\u300d\u3068\u300cviews\/Member\/index.twig\u300d\u304c\u4fdd\u5b58\u3057\u3066\u3042\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u306f\u540d\u524d\u3092\u3064\u3051\u3088\u3046<\/h3>\n<p>Laravel\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u306f\u3001\u5225\u540d\u3092\u4ed8\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u5225\u540d\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u3001URL\u304c\u5909\u308f\u3063\u305f\u308a\u3001\u547c\u3073\u51fa\u3057\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304c\u5909\u308f\u3063\u3066\u3082\u3001\u547c\u3073\u51fa\u3057\u5074\u306b\u5f71\u97ff\u304c\u51fa\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:php decode:true \" >Route::get('\/item', 'ItemController@index')-&gt;name('item.index');\r\nRoute::get('\/member', 'MemberController@index')-&gt;name('member.index');\r\n<\/pre>\n<p>\u300cname\u300d\u306b\u304b\u304b\u308c\u3066\u3044\u308b\u300c&#8217;item.index&#8217;\u300d\u3084\u300c&#8217;member.index&#8217;\u300d\u304c\u5225\u540d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3067\u3001\u6e96\u5099\u304c\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<h2>\u73fe\u5728\u306eURL\u3092\u53d6\u5f97\u3057\u3066\u307f\u3088\u3046<\/h2>\n<p>\u300c\u73fe\u5728\u306eURL\u300d\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30fc\u30c9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \" >{{ url().current() }}\r\n<\/pre>\n<p>\u300curl()\u300d\u306f\u3001Laravel\u306e\u300curl\u95a2\u6570\u300d\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u672c\u6765\u306f\u3001\u5f15\u6570\u306b\u30d1\u30b9\uff08\u4f8b\uff1a&#8217;\/item&#8217;\uff09\u3092\u6e21\u3059\u3053\u3068\u3067\u3001\u5b8c\u5168\u306aURL\uff08http:\/\/\u304b\u3089\u59cb\u307e\u308bURL\uff09\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u307e\u307e\u3067\u306f\u3001\u300c\u73fe\u5728\u306eURL\u300d\u3092\u53d6\u5f97\u3057\u305f\u3060\u3051\u3067\u3001\u5b9f\u969b\u306b\u30e1\u30cb\u30e5\u30fc\u3092\u30a2\u30af\u30c6\u30a3\u30d6\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u6761\u4ef6\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>Twig\u306e\u300cmatch\u300d\u3092\u4f7f\u3063\u3066\u3001\u30da\u30fc\u30b8\u3092\u8a8d\u8b58\u3055\u305b\u308b<\/h2>\n<p>\u5148\u7a0b\u3001\u53d6\u5f97\u3057\u305f\u300c\u73fe\u5728\u306eURL\u300d\u3092\u5229\u7528\u3057\u3066\u3001\u73fe\u5728\u306eURL\u304c\u30e1\u30cb\u30e5\u30fc\u306b\u8a72\u5f53\u3059\u308bURL\u306a\u306e\u304b\u3092\u5224\u5b9a\u3059\u308b\u30b3\u30fc\u30c9\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u6761\u4ef6\u5f0f\u306b\u5229\u7528\u3059\u308b\u306e\u306f\u3001Twig\u306e\u300cmatches\u300d\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \" >{%  if url().current() matches '{item}' %}\r\n    \u5546\u54c1\u30da\u30fc\u30b8\u3067\u3059\u3002\r\n{% elseif url().current() matches '{member}' %}\r\n    \u30e1\u30f3\u30d0\u30fc\u30da\u30fc\u30b8\u3067\u3059\u3002\r\n{% endif %}<\/pre>\n<p>\u5148\u7a0b\u306e\u300curl().current()\u300d\u3092\u4f7f\u3044\u305d\u306e\u6587\u5b57\u5217\u306b\u300c'{member}&#8217;\u300d\u3092\u542b\u3093\u3067\u3044\u308c\u3070\u300ctrue\u300d\u3068\u3044\u3046\u6761\u4ef6\u5f0f\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>Twig\u306e\u300cmatches\u300d\u306f\u3001\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u3044\u8907\u96d1\u306a\u6587\u5b57\u691c\u7d22\u3092\u53ef\u80fd\u306b\u3057\u307e\u3059\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u300c\u73fe\u5728\u306eURL\u300d\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u7c21\u5358\u306b\u30a2\u30af\u30c6\u30a3\u30d6\u30da\u30fc\u30b8\u306e\u51e6\u7406\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059<\/p>\n<p>\u305f\u3060\u3057\u3001\u300c\u73fe\u5728\u306eURL\u300d\u306e\u53d6\u5f97\u65b9\u6cd5\u306f\u3001\u540c\u3058Twig\u3092\u5229\u7528\u3057\u3066\u3044\u3066\u3082\u3001\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u7a2e\u985e\u306b\u3088\u3063\u3066\u547c\u3073\u51fa\u3057\u65b9\u304c\u5909\u308f\u3063\u3066\u304d\u307e\u3059\u306e\u3067\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<h3>\u73fe\u5834\u306e\u696d\u52d9\u30d5\u30ed\u30fc\u306b\u5bc4\u308a\u6dfb\u3063\u305fWeb\u30b7\u30b9\u30c6\u30e0\u3092\u304a\u6c42\u3081\u306a\u3089\u3001\u79c1\u305f\u3061ALAKI\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/h3>\n<p>ALAKI\u306f\u7d4c\u55b6\u8005\u69d8\u304c\u611f\u3058\u3066\u3044\u308b\u554f\u984c\u70b9\u3068\u3001\u5b9f\u969b\u306bWeb\u30b7\u30b9\u30c6\u30e0\u3092\u5229\u7528\u3055\u308c\u308b\u73fe\u5834\u30b9\u30bf\u30c3\u30d5\u69d8\u304c\u76f4\u9762\u3057\u3066\u3044\u308b\u8ab2\u984c\u3092\u3001\u5f0a\u793e\u30b7\u30b9\u30c6\u30e0\u30a8\u30f3\u30b8\u30cb\u30a2\u304c\u4e01\u5be7\u306b\u805e\u304d\u53d6\u308a\u3001\u304a\u5ba2\u69d8\u3068\u5171\u306b\u30b7\u30b9\u30c6\u30e0\u3092\u4f5c\u308a\u4e0a\u3052\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u696d\u52d9\u6539\u5584\u304c\u5b9f\u73fe\u3067\u304d\u308bWeb\u30b7\u30b9\u30c6\u30e0\u3092\u304a\u6c42\u3081\u306e\u65b9\u306f\u3001\u662f\u975eALAKI\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/websystem\/\">\u30fbALAKI\u306eWeb\u30b7\u30b9\u30c6\u30e0\u958b\u767a<\/a><\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/lp\/cloud-ordering-system\/\">\u30fbALAKI\u306e\u30af\u30e9\u30a6\u30c9\u578b\u53d7\u767a\u6ce8\u30b7\u30b9\u30c6\u30e0<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001Web\u30d7\u30ed\u30b0\u30e9\u30de\u306e\u7be0\u7530\u3067\u3059\u3002 \u4eca\u56de\u306f\u3001PHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":2927,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[33,16],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2961"}],"collection":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2961"}],"version-history":[{"count":5,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2961\/revisions"}],"predecessor-version":[{"id":3435,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2961\/revisions\/3435"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/2927"}],"wp:attachment":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2961"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}