{"id":2537,"date":"2018-11-20T03:52:57","date_gmt":"2018-11-19T18:52:57","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2537"},"modified":"2018-11-20T03:52:57","modified_gmt":"2018-11-19T18:52:57","slug":"laravel%e3%81%a7url%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b%e5%85%a8%ef%bc%96%e9%a0%85%e7%9b%ae%e3%83%bb%e5%ae%9f%e4%be%8b%ef%bc%81","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2537","title":{"rendered":"Laravel\u3067URL\u3092\u53d6\u5f97\u3059\u308b\u5168\uff16\u9805\u76ee\u30fb\u5b9f\u4f8b\uff01"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Laravel\u3092\u4f7f\u3063\u305f\u958b\u767a\u3067\u306f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u5834\u5408\u306a\u3069\u3001\u3057\u3070\u3057\u3070\u3042\u308b\u7279\u5b9a\u306eURL\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304f\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093URL\u3092\u76f4\u63a5 <code>https:\/\/****.com\/test1\/test2<\/code>\u00a0\u3068\u3044\u3046\u3088\u3046\u306b\u76f4\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u3082\u3044\u3044\u306e\u306f\u3044\u3044\u306e\u3067\u3059\u304c\u3001Laravel\u306b\u306f\u30d1\u30e9\u30e1\u30fc\u30bf\u3064\u304d\u3067URL\u3092\u53d6\u5f97\u3057\u305f\u308a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3084\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304b\u3089\u3082URL\u304c\u53d6\u5f97\u3067\u304d\u308b\u305f\u3081\u3001\u3053\u308c\u3089\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u77e5\u3063\u3066\u3044\u308b\u3068\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u304c\u3068\u3066\u3082\u697d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u7279\u306b\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u540d\u3092\u4f7f\u3063\u3066URL\u3092\u53d6\u5f97\u3057\u3066\u304a\u304f\u3068\u3001\u305d\u306e\u5f8c\u30b5\u30a4\u30c8\u69cb\u6210\u304c\u5909\u308f\u3063\u3066\u3057\u307e\u3063\u3066\u3082\u305d\u306e\u307e\u307eURL\u306f\u81ea\u52d5\u7684\u306b\u5207\u308a\u66ff\u308f\u308a\u307e\u3059\u3057\u4fdd\u5b88\u7684\u306b\u3082\u30d7\u30e9\u30b9\u306a\u90e8\u5206\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306fLaravel\u3067URL\u3092\u53d6\u5f97\u3059\u308b\u5168\u5b9f\u4f8b\u3092\u304a\u5c4a\u3051\u3057\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u958b\u767a\u306e\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-417 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png\" alt=\"\" width=\"370\" height=\"220\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9-300x178.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>\u203b Laravel\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff1a \uff15\uff0e\uff17<\/p>\n<h1>\u5b9f\u884c\u74b0\u5883\u306b\u3064\u3044\u3066<\/h1>\n<p>\u4eca\u56de\u7d39\u4ecb\u3059\u308b\u5168\u3066\u306e\u30b3\u30fc\u30c9\u306f<code>http:\/\/example.test<\/code>\u3068\u3044\u3046\u30ed\u30fc\u30ab\u30eb\u30b5\u30a4\u30c8\u3067\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u3054\u81ea\u8eab\u306e\u74b0\u5883\u3067\u5b9f\u884c\u3057\u305f\u5834\u5408\u3068\u30c9\u30e1\u30a4\u30f3\u90e8\u5206\u304c\u9055\u3063\u3066\u304d\u307e\u3059\u306e\u3067\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u57fa\u672c\u7684\u306aURL\u306e\u53d6\u5f97\u65b9\u6cd5\uff1a url()<\/h1>\n<p>\u307e\u305aLaravel\u3067\u4e00\u756a\u57fa\u672c\u7684\u306aURL\u306e\u53d6\u5f97\u65b9\u6cd5\u306f\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u306e<code>url()<\/code>\u3092\u4f7f\u3063\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<h2>\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306eURL\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p><code>url()<\/code>\u306e\u5f15\u6570\u306b\u7a7a\u767d\u3001\u3082\u3057\u304f\u306f<code>\/<\/code>\u3092\u6307\u5b9a\u3059\u308b\u3068\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>echo <strong>url('');<\/strong><\/pre>\n<pre>echo <strong>url('\/');<\/strong><\/pre>\n<h2>\u30da\u30fc\u30b8\u3092\u6307\u5b9a\u3057\u3066URL\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>http:\/\/example.test\/xxx.html<\/code>\u3068\u3044\u3046URL\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<br \/>\n\u3053\u306e\u5834\u5408\u3001<code>url()<\/code>\u306e\u5f15\u6570\u306b\u76f4\u63a5<code>xxx.html<\/code>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>echo <strong>url('xxx.html');<\/strong><\/pre>\n<h2>\u968e\u5c64\u304c\u6df1\u3044\u30da\u30fc\u30b8\u3092\u6307\u5b9a\u3057\u3066URL\u3092\u6307\u5b9a\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>http:\/\/example.test\/xxx\/yyy\/zzz<\/code>\u3068\u3044\u3046URL\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002\u540c\u3058\u304f\u5f15\u6570\u306b\u53d6\u5f97\u3057\u305f\u3044\u968e\u5c64\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>echo <strong>url('xxx\/yyy\/zzz');<\/strong><\/pre>\n<p>\u3082\u3057\u304f\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u7b2c\uff12\u5f15\u6570\u306b\u914d\u5217\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>echo <strong>url('\/', ['xxx', 'yyy', 'zzz']);<\/strong><\/pre>\n<h2>\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u3064\u3051\u305fURL\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>http:\/\/example.test\/xxx?key=value<\/code>\u3068\u3044\u3046URL\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>echo <strong>url('xxx?key=value');<\/strong><\/pre>\n<h2>https:\/\/\u304b\u3089\u59cb\u307e\u308bURL\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>http<strong>s<\/strong>:\/\/example.test<\/code>\u3068\u3044\u3046URL\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3067\u3059\u3002<br \/>\n\u3053\u306e\u5834\u5408\u3001\u7b2c\uff13\u5f15\u6570\u306b<code>true<\/code>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>echo url('\/', null, <strong>true<\/strong>);<\/pre>\n<h2>\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u542b\u307e\u306a\u3044\u73fe\u5728\u306eURL\u3092\u53d6\u5f97\u3059\u308b\uff1a current()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u73fe\u5728\u306eURL\u304c<code>\"http:\/\/example.test\/xxx?key=value\"<\/code>\u3060\u3063\u305f\u3068\u3057\u3066\u3001<code>\"http:\/\/example.test\/xxx\"<\/code>\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>echo <strong>url()-&gt;current();<\/strong><\/pre>\n<h2>\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u542b\u3080\u73fe\u5728\u306eURL\u3092\u53d6\u5f97\u3059\u308b\uff1a full()<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u73fe\u5728\u306eURL\u304c<code>\"http:\/\/example.test\/xxx?key=value\"<\/code>\u3060\u3063\u305f\u3068\u3057\u3066\u3001 \u305d\u306e\u307e\u307e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u542b\u3081\u305f<code>\"http:\/\/example.test\/xxx?key=value\"<\/code>\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>echo <strong>url()-&gt;full();<\/strong><\/pre>\n<h2>\u76f4\u524d\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3055\u308c\u305fURL\u3092\u53d6\u5f97\u3059\u308b\uff1a previous()<\/h2>\n<pre>echo <strong>url()-&gt;previous();<\/strong><\/pre>\n<h1>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u4f7f\u3063\u305fURL\u306e\u53d6\u5f97<\/h1>\n<p><a href=\"https:\/\/blog.capilano-fw.com\/?p=837\">\u5168120\u7a2e\u985e\uff01Laravel5.6\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u5b9f\u4f8b<\/a> \u306e <a href=\"https:\/\/blog.capilano-fw.com\/?p=837#routeURL\" target=\"_blank\" rel=\"noopener\">route()\u3067\u30eb\u30fc\u30c8\u540d\u3092\u6307\u5b9a\u3057\u3066URL\u3092\u53d6\u5f97\u3059\u308b<\/a> \u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f7f\u3063\u305fURL\u306e\u53d6\u5f97<\/h1>\n<p><a href=\"https:\/\/blog.capilano-fw.com\/?p=837\">\u5168120\u7a2e\u985e\uff01Laravel5.6\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u5b9f\u4f8b<\/a> \u306e <a href=\"https:\/\/blog.capilano-fw.com\/?p=837#actionURL\" target=\"_blank\" rel=\"noopener\">action()\u3067\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3068\u30a2\u30af\u30b7\u30e7\u30f3\u304b\u3089URL\u3092\u53d6\u5f97\u3059\u308b<\/a> \u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u7f72\u540d\u3064\u304dURL\u3092\u53d6\u5f97\u3059\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u6b21\u306e\u3088\u3046\u306a\u6d41\u308c\u3092\u8003\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<ol>\n<li>\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u5909\u66f4\u7533\u8acb\u3092\u3059\u308b<\/li>\n<li>\u7f72\u540d\u3064\u304d\uff08\u4e00\u610f\u306a\u6587\u5b57\u5217\u304c\u3064\u3044\u305f\uff09URL\u304c\u30e1\u30fc\u30eb\u9001\u4fe1\u3055\u308c\u3066\u304f\u308b<\/li>\n<li>\u305d\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u5909\u66f4\u304c\u3067\u304d\u308b<\/li>\n<\/ol>\n<p>\u3053\u306e\u5834\u5408\u306e\uff12\u756a\u76ee\u306e\u9805\u76ee\u3067\u5fc5\u8981\u306b\u306a\u308b\u7f72\u540d\u4ed8\u304dURL\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<h2>URL\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u3067\u306f\u3053\u306eURL\u306e\u53d6\u5f97\u65b9\u6cd5\u3067\u3059\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u307e\u305a\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002<\/span><\/p>\n<pre><strong>Route::get('user\/password_reset', 'User\\HomeController@password_reset')-&gt;name('user.password_reset');<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001<code>URL::signedRoute()<\/code>\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>use Illuminate\\Support\\Facades\\URL;<\/strong><\/pre>\n<pre>echo <strong>URL::signedRoute('user.password_reset', ['user_id' =&gt; 1]);<\/strong><\/pre>\n<p>\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306aURL\u3092\u767a\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><code>http:\/\/example.test\/user\/password_reset?user_id=1&amp;signature=757ae5fea4f5b7cecc9aa741a378d4fc25aeaac758c27d9d06f92c562a660faf<\/code><\/p>\n<p>\u3053\u306e<code>signature<\/code>\u306e\u90e8\u5206\u304c\u7f72\u540d\u3067\u3001\u4e00\u610f\u306a\u6587\u5b57\u5217\u306b\u306a\u308a<span style=\"font-size: 1rem;\">\u3001<\/span><span style=\"font-size: 1rem;\">\u5f8c\u308d\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u5909\u308f\u308b\u3068\u6587\u5b57\u5217\u306f\u5909\u66f4\u306b\u306a\u308a\u307e\u3059\u3002<\/span><\/p>\n<p>\u307e\u305f\u3001\u5236\u9650\u6642\u9593\u304c\u3042\u308b\u7f72\u540dURL\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\uff08\u3064\u307e\u308a\u3001\u300c\u3053\u306e\u30ea\u30f3\u30af\u306e\u6709\u52b9\u6642\u9593\u306f24\u6642\u9593\u3067\u3059\u300d\u3068\u3044\u3046\u6642\u9593\u5236\u9650\u304c\u3042\u308bURL\u306b\u306a\u308a\u307e\u3059\uff09<\/p>\n<pre><strong>use Illuminate\\Support\\Facades\\URL;<\/strong><\/pre>\n<pre>$expire = now()-&gt;addHours(24);\r\n\r\necho <strong>URL::temporarySignedRoute(<\/strong>\r\n<strong>    'user.password_reset',  \/\/ \u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u540d<\/strong>\r\n<strong>    $expire,                \/\/ \u6709\u52b9\u671f\u9650\uff08\u3053\u306e\u5834\u540824\u6642\u9593\uff09<\/strong>\r\n<strong>    ['user_id' =&gt; 1]        \/\/ \u30d1\u30e9\u30e1\u30fc\u30bf<\/strong>\r\n<strong>)<\/strong>;<\/pre>\n<p>\u5b9f\u969b\u306b\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u305f\u3082\u306e\u304c\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><code>http:\/\/example.test\/user\/password_reset?expires=1542652227&amp;user_id=1&amp;signature=4bcc7e874128d6f10071f3dd746cde4bf1a92065d44ca2b1ef0ce2c1fe6d4366<\/code><\/p>\n<h2>\u53d6\u5f97\u3057\u305f\u7f72\u540d\u3064\u304dURL\u304c\u6709\u52b9\u304b\u30c1\u30a7\u30c3\u30af\u3059\u308b<\/h2>\n<h3>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u5185\u3067\u30c1\u30a7\u30c3\u30af\u3059\u308b\u65b9\u6cd5<\/h3>\n<p>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u5185\u3067<code>hasValidSignature()<\/code>\u3092\u4f7f\u3046\u3053\u3068\u3067URL\u304c\u6709\u52b9\u304b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>Route::get('user\/password_reset', function (\\Illuminate\\Http\\Request $request) {\r\n\r\n    if(<strong>!$request-&gt;hasValidSignature()<\/strong>) {\r\n\r\n        return redirect('\/'); \/\/\u3000\u7121\u52b9\u306e\u5834\u5408\u306f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\r\n\r\n    }\r\n\r\n})-&gt;name('user.password_reset');<\/pre>\n<h3>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f7f\u3046\u65b9\u6cd5<\/h3>\n<p>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u5185\u3067\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3068\u30b3\u30fc\u30c9\u304c\u5897\u3048\u3066\u3057\u307e\u3044\u53ef\u8aad\u6027\u304c\u60aa\u304f\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u305d\u3093\u306a\u5834\u5408\u306f\u5c02\u7528\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f7f\u3063\u3066\u7f72\u540dURL\u304c\u6709\u52b9\u304b\u7121\u52b9\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001<code>app\/Http\/Kernel.php<\/code>\u3092\u958b\u3044\u3066<code>$routeMiddleware<\/code>\u306b<code>ValidateSignature<\/code>\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\uff08\u3061\u306a\u307f\u306b\u79c1\u306e\u74b0\u5883\u3067\u306f\u3059\u3067\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u307e\u3057\u305f\uff09<\/p>\n<pre>protected $routeMiddleware = [\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>'signed' =&gt; \\Illuminate\\Routing\\Middleware\\ValidateSignature::class,<\/strong>\r\n];<\/pre>\n<p>\u3053\u308c\u3067<code>signed<\/code>\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3067\u6b21\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>Route::get('user\/password_reset', 'User\\HomeController@password_reset')\r\n    -&gt;name('user.password_reset')\r\n    <strong>-&gt;middleware('signed');<\/strong><\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u3082\u3057\u7121\u52b9\u306aURL\u306b\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305f\u3089403\u30b3\u30fc\u30c9\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2538\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_403.png\" alt=\"\" width=\"385\" height=\"389\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_403.png 385w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_403-297x300.png 297w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_403-100x100.png 100w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/p>\n<p>\u3082\u3057\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u72ec\u81ea\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f5c\u6210\u3057\u3066\u4f7f\u3046\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Middleware;\r\n\r\nuse Closure;\r\n\r\nclass <strong>ValidationSignatureRedirect<\/strong>\r\n{\r\n    \/**\r\n     * Handle an incoming request.\r\n     *\r\n     * @param  \\Illuminate\\Http\\Request  $request\r\n     * @param  \\Closure  $next\r\n     * @return mixed\r\n     *\/\r\n    public function handle($request, Closure $next)\r\n    {\r\n        if ($request-&gt;hasValidSignature()) {\r\n            return $next($request);\r\n        }\r\n\r\n        <strong>return redirect('\/');<\/strong>\r\n    }\r\n}<\/pre>\n<h1>\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u306b\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3059\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u3082\u3057\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u3068\u304d\u306fURL\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30e6\u30fc\u30b6\u30fc\u540d\u304c\u5165\u3063\u3066\u304f\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>http:\/\/example.test\/<strong>username<\/strong>\/xxx.html<\/li>\n<li>http:\/\/example.test\/<strong>username<\/strong>\/yyy\/zzz<\/li>\n<\/ul>\n<p>\u3053\u306e\u5834\u5408\u3001\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>Route::get('{username}\/xxx.html', 'HomeController@xxx')-&gt;name('xxx');<\/strong>\r\n<strong>Route::get('{username}\/yyy\/zzz', 'HomeController@yyy_zzz')-&gt;name('yyy.zzz');<\/strong><\/pre>\n<p>\u3067\u306f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f7f\u3063\u3066\u3053\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6b21\u306e\u30eb\u30fc\u30eb\u3067\u8a2d\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u5834\u5408\u3000\u30fb\u30fb\u30fb\u3000\u30e6\u30fc\u30b6\u30fc\u540d<\/li>\n<li>\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u3000\u30fb\u30fb\u30fb\u3000guest<\/li>\n<\/ul>\n<p>\u307e\u305a\u5c02\u7528\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan make:middleware SetDefaultUserName<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u4f5c\u6210\u3055\u308c\u305f<code>app\/Http\/Middleware\/SetDefaultUserName.php<\/code>\u3092\u958b\u3044\u3066\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Middleware;\r\n\r\nuse Closure;\r\nuse Illuminate\\Support\\Facades\\URL;\r\n\r\nclass SetDefaultUserName\r\n{\r\n    \/**\r\n     * Handle an incoming request.\r\n     *\r\n     * @param  \\Illuminate\\Http\\Request  $request\r\n     * @param  \\Closure  $next\r\n     * @return mixed\r\n     *\/\r\n    public function handle($request, Closure $next)\r\n    {\r\n        $username = (auth()) ? auth()-&gt;user()-&gt;name : 'guest';\r\n        <strong>URL::defaults(['username' =&gt; $username]);<\/strong>\r\n\r\n        return $next($request);\r\n    }\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092<code>app\/Http\/Kernel.php<\/code>\u3078\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>protected $middlewareGroups = [\r\n    'web' =&gt; [\r\n\r\n        \/\/ \u7701\u7565\r\n\r\n        <strong>SetDefaultUserName::class,<\/strong>\r\n    ],\r\n\r\n    \/\/ \u7701\u7565\r\n];<\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u306f<strong> &#8220;route middleware&#8221;<\/strong> \u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u304c<code>$routeMIddleware<\/code>\u3078\u767b\u9332\u3057\u3066\u3082\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5148\u307b\u3069\u306e\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3066\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u9069\u7528\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>Route::<strong>middleware('default_user_name')<\/strong>-&gt;group(function(){\r\n\r\n    Route::get('{username}\/xxx.html', function(){})-&gt;name('xxx');\r\n    Route::get('{username}\/yyy\/zzz', function(){})-&gt;name('yyy.zzz');\r\n\r\n});<\/pre>\n<p>\u3053\u308c\u3067\u3001<code>route()<\/code>\u306b\u521d\u671f\u5024\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<pre><strong>echo route('xxx');<\/strong><\/pre>\n<p>\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\u30d1\u30e9\u30e1\u30fc\u30bf\u306a\u3057\u3067\u3082\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\uff08\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u306a\u3044\u6642\uff09<\/p>\n<pre><strong>http:\/\/example.test\/guest\/xxx.html<\/strong><\/pre>\n<p>\uff08\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u6642\uff09<\/p>\n<pre><strong>http:\/\/example.test\/taro\/xxx.html<\/strong><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Laravel\u3092\u4f7f\u3063\u305f\u958b\u767a\u3067\u306f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u5834\u5408\u306a\u3069\u3001\u3057\u3070\u3057\u3070\u3042\u308b\u7279\u5b9a\u306eURL\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304f\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002 \u3082\u3061\u308d\u3093URL\u3092\u76f4\u63a5 http &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2537\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel\u3067URL\u3092\u53d6\u5f97\u3059\u308b\u5168\uff16\u9805\u76ee\u30fb\u5b9f\u4f8b\uff01&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2544,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[117],"class_list":["post-2537","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-url"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2537","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=2537"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2537\/revisions"}],"predecessor-version":[{"id":2546,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2537\/revisions\/2546"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2544"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}