{"id":3987,"date":"2019-06-28T00:47:03","date_gmt":"2019-06-27T15:47:03","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=3987"},"modified":"2019-06-28T00:47:06","modified_gmt":"2019-06-27T15:47:06","slug":"%e3%80%90laravel-5-8-%e3%80%91%e3%80%8c%e3%81%93%e3%82%93%e3%81%aa%e3%81%a8%e3%81%8d%e3%80%8d%e3%81%ae%e3%83%9f%e3%83%89%e3%83%ab%e3%82%a6%e3%82%a7%e3%82%a2%e5%85%a8%ef%bc%97%e5%ae%9f%e4%be%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=3987","title":{"rendered":"\u3010Laravel 5.8 \u3011\u300c\u3053\u3093\u306a\u3068\u304d\u300d\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u5168\uff17\u5b9f\u4f8b\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u304c<code>Laravel<\/code>\u3092\u4f7f\u3044\u59cb\u3081\u305f\u306e\u306f\u30d0\u30fc\u30b8\u30e7\u30f3<code>4.2<\/code>\u304c\u51fa\u3066\u3059\u3050\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u73fe\u5728\u306f\u3059\u3067\u306b\u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\u304c<code>5.8<\/code>\u306b\u306a\u308a\u3001\u3061\u3089\u307b\u3089<code>5.9<\/code>\u306e\u8a71\u984c\u3082\u30cb\u30e5\u30fc\u30b9\u3068\u3057\u3066\u307f\u304b\u3051\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u524d\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u3088\u304f\u4f7f\u3063\u3066\u3044\u305f\u958b\u767a\u8005\u304b\u3089\u3059\u308b\u3068\u300c\u4eca\u306f\u666e\u901a\u306b\u4f7f\u3063\u3066\u3044\u308b\u3051\u3069\u3001\u3059\u3054\u304f\u5f37\u529b\u306a\u6a5f\u80fd\u300d\u306e\u4fbf\u5229\u3055\u3092\u518d\u8a8d\u8b58\u3059\u308b\u5834\u9762\u304c\u7d50\u69cb\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u306e\u4e2d\u306e\u3072\u3068\u3064\u304c\u4eca\u56de\u306e\u8a71\u984c\u300c\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u300d\u3067\u3059\u3002<\/p>\n<p>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3068\u306f\u3001<strong>\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u76f4\u524d\u306b\u5b9f\u884c\u3055\u308c\u308b\u3082\u306e<\/strong>\u3067\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u305f\u308a\u5225\u306e\u30da\u30fc\u30b8\u3092\u898b\u305b\u308b\u3068\u3044\u3063\u305f\u3053\u3068\u304c\u7c21\u5358\u306b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\uff08\u4f8b\u3048\u3070\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3057\u304b\u898b\u3089\u308c\u306a\u3044\u30da\u30fc\u30b8\u3082\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u3072\u3068\u3064\u3067\u3059\u306d\uff09<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u3053\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068\u300c\u3053\u3093\u306a\u3068\u304d\u300d\u306b\u4f7f\u3048\u308b\u30b5\u30f3\u30d7\u30eb\u3092\u5b9f\u4f8b\u3067\u7d39\u4ecb\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u3001\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<br \/>\n\u6700\u5f8c\u306b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3344 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22.png\" alt=\"\" width=\"320\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22.png 320w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-150x150.png 150w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-300x300.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-100x100.png 100w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/p>\n<p>\u958b\u767a\u74b0\u5883\uff1a Laravel 5.8<\/p>\n<h1>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h1>\n<h2>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u4f5c\u308a\u65b9<\/h2>\n<p>Laravel\u306b\u306f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f5c\u6210\u3059\u308b\u30b3\u30de\u30f3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u3044\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u7ba1\u7406\u8005\u3060\u3051\u304c\u898b\u3089\u308c\u308b\u3088\u3046\u306a\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan make:middleware AdminAuth<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>app\/Http\/Middleware\/AdminAuth.php<\/code>\u304c\u4f5c\u6210\u3055\u308c\u3001\u4e2d\u8eab\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;?php<\/strong>\n\n<strong>namespace App\\Http\\Middleware;<\/strong>\n\n<strong>use Closure;<\/strong>\n\n<strong>class AdminAuth<\/strong>\n<strong>{<\/strong>\n<strong>    public function handle($request, Closure $next)<\/strong>\n<strong>    {<\/strong>\n<strong>        return $next($request);<\/strong>\n<strong>    }<\/strong>\n<strong>}<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u4e2d\u306b\u7ba1\u7406\u8005\u3060\u3051\u304c\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\u4f8b\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>public function handle($request, Closure $next)\n{\n    <strong>if(auth()-&gt;check() &amp;&amp; auth()-&gt;user()-&gt;role === 'admin') {<\/strong>\n\n<strong>        return $next($request);<\/strong>\n\n<strong>    }<\/strong>\n\n<strong>    abort(403, '\u7ba1\u7406\u8005\u6a29\u9650\u304c\u3042\u308a\u307e\u305b\u3093\u3002');<\/strong>\n}<\/pre>\n<p>\u3064\u307e\u308a\u3001<code>return $next($request);<\/code>\u3092\u5b9f\u884c\u3059\u308c\u3070\u901a\u5e38\u901a\u308a\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u6761\u4ef6\u304c\u5408\u308f\u306a\u304b\u3063\u305f\u3068\u304d\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>public function handle($request, Closure $next)\n{\n    <strong>if(auth()-&gt;check() &amp;&amp; auth()-&gt;user()-&gt;role === 'admin') {<\/strong>\n\n<strong>        return $next($request);<\/strong>\n\n<strong>    }<\/strong>\n\n<strong>    return redirect('\/');<\/strong>\n}<\/pre>\n<h2>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u8a2d\u7f6e\u65b9\u6cd5<\/h2>\n<h3>\u7279\u5b9a\u306e\u30da\u30fc\u30b8\u306e\u307f\u6709\u52b9\u306b\u3059\u308b<\/h3>\n<p>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306f\u4f5c\u6210\u3057\u305f\u3060\u3051\u3067\u306f\u6709\u52b9\u306b\u306a\u308a\u307e\u305b\u3093\u3002\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u6709\u52b9\u306b\u3059\u308b\u306b\u306f\u3001<code>app\/Http\/Kernel.php<\/code>\u306b\u767b\u9332\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3042\u308b\u7279\u5b9a\u306e\u30da\u30fc\u30b8\u3060\u3051\u3067\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u6709\u52b9\u306b\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u306e<code>$routeMiddleware<\/code>\u306b\u767b\u9332\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>protected <strong>$routeMiddleware<\/strong> = [\n\n    \/\/ \u7701\u7565\n\n    <strong>'admin_auth' =&gt; \\App\\Http\\Middleware\\AdminAuth::class<\/strong>\n];<\/pre>\n<p>\u305d\u3057\u3066\u3001\u767b\u9332\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u6b21\u306f\u5b9f\u969b\u306e\u30eb\u30fc\u30c8\u306b\u9069\u7528\u3055\u305b\u307e\u3059\u3002<\/p>\n<pre>Route::get('admin', 'AdminController@index')-&gt;<strong>middleware('admin_auth')<\/strong>;<\/pre>\n<p>\u3053\u308c\u3067<code>http:\/\/******\/admin<\/code>\u306b\u306f<code>AdminAuth<\/code>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u304c\u9069\u7528\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u3053\u306e\u65b9\u6cd5\u3067\u306f\u30da\u30fc\u30b8\u304c\u5897\u3048\u3066\u3044\u304f\u3054\u3068\u306b\u6bce\u56de<code>middleware()<\/code>\u3092\u66f8\u304b\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u306e\u3067\u5c11\u3057\u3081\u3093\u3069\u3046\u3067\u3059\u3088\u306d\u3002\u305d\u306e\u5834\u5408\u306b\u306f\u6b21\u306e\u3088\u3046\u306b<code>group()<\/code>\u3092\u4f7f\u3063\u3066\u4e00\u6c17\u306b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>Route::group(['middleware' =&gt; 'admin_auth'], function(){<\/strong>\n\n<strong>    \/\/ \u3053\u306e\u4e2d\u306f\u3001\u5168\u3066\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u304c\u9069\u7528\u3055\u308c\u307e\u3059\u3002<\/strong>\n<strong>    Route::get('middleware_test', 'HomeController@middleware_test');<\/strong>\n\n<strong>});<\/strong><\/pre>\n<p>\u3055\u3089\u306b\u3001\u5b9f\u306f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u3082\u8a2d\u7f6e\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3066\u3001\u305d\u306e\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>__construct()<\/code>\u5185\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre>class HomeController extends Controller\n{\n    <strong>public function __construct() {<\/strong>\n\n<strong>        $this-&gt;middleware('admin_auth');<\/strong>\n\n<strong>        \/\/ \u3082\u3057\u304f\u306f\u3001\u300c\u7279\u5b9a\u306e\u30e1\u30bd\u30c3\u30c9\u3060\u3051\u300d\u304b\u300c\u7279\u5b9a\u306e\u30e1\u30bd\u30c3\u30c9\u4ee5\u5916\u300d<\/strong>\n<strong>        $this-&gt;middleware('admin_auth')-&gt;only(['index', 'create']);<\/strong>\n<strong>        $this-&gt;middleware('admin_auth')-&gt;except(['edit', 'destroy']);<\/strong>\n\n<strong>    }<\/strong><\/pre>\n<h3>\u5168\u3066\u306e\u30da\u30fc\u30b8\u3067\u6709\u52b9\u306b\u3059\u308b<\/h3>\n<p>\u7d9a\u3044\u3066\u3001\u5168\u3066\u306e\u30da\u30fc\u30b8\u3067\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u6709\u52b9\u306b\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002\u3053\u306e\u5834\u5408\u3001<code>app\/Http\/Kernel.php<\/code>\u5185\u306e<code>$middlewareGroups<\/code>\u306b\u4f5c\u6210\u3057\u305f\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u767b\u9332\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>protected <strong>$middlewareGroups<\/strong> = [\n    'web' =&gt; [\n\n        \/\/ \u7701\u7565\n\n        <strong>\\App\\Http\\Middleware\\AdminAuth::class,<\/strong>\n    ],<\/pre>\n<p>\u3053\u308c\u3067\u5168\u3066\u306e\u30da\u30fc\u30b8\u306b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u9069\u7528\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f\u4ee5\u4e0a\u3067\u3059\u306e\u3067\u3001\u6b21\u306e\u9805\u76ee\u304b\u3089\u306f\u5b9f\u969b\u306e\u30b1\u30fc\u30b9\u30b9\u30bf\u30c7\u30a3\u3067\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1>\u3053\u3093\u306a\u3068\u304d\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u30fb\u5b9f\u4f8b<\/h1>\n<h2>HTTPS\u63a5\u7d9a\u306e\u307f\u3092\u8a31\u53ef\u3059\u308b\uff08\u81ea\u52d5\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\uff09<\/h2>\n<p>\u3082\u3057HTTP\u3067\u63a5\u7d9a\u3057\u3066\u304d\u305f\u5834\u5408\u306f\u5f37\u5236\u7684\u306bHTTPS\u306eURL\u306b\u8ee2\u9001\u3059\u308b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\n\nclass <strong>OnlyHttps<\/strong>\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>if(!$request-&gt;secure() &amp;&amp; env('APP_ENV') === 'production') {<\/strong>\n\n<strong>            return redirect()-&gt;secure($request-&gt;getRequestUri());<\/strong>\n            \n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<p>IF\u6587\u306e\u4e2d\u8eab\u3068\u3057\u3066\u306f\u3001<\/p>\n<ul>\n<li>HTTP\u3067\u63a5\u7d9a\u3057\u3066\u3044\u308b\u304b\uff1f<\/li>\n<li>\u5b9f\u884c\u74b0\u5883\u304c production\uff08\u3064\u307e\u308a\u672c\u756a\u74b0\u5883\uff09\u304b\uff1f<\/li>\n<\/ul>\n<p>\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u3082\u3057\u4e21\u65b9\u3068\u3082<code>true<\/code>\u3067\u3042\u308c\u3070\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3068\u3044\u3046\u6d41\u308c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u7279\u5b9a\u306eIP\u30a2\u30c9\u30ec\u30b9\u3060\u3051\u8a31\u53ef\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u3042\u308b\u7279\u5b9a\u306eIP\u30a2\u30c9\u30ec\u30b9\u3060\u3051\u304b\u3089\u3057\u304b\u30da\u30fc\u30b8\u3092\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u304f\u306a\u308b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\n\nclass <strong>IpAddress<\/strong>\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>if($request-&gt;ip() !== '111.111.111.111') {<\/strong>\n\n<strong>            return redirect('\/');<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<p>\u306a\u304a\u3001IP\u30a2\u30c9\u30ec\u30b9\u3092\u7bc4\u56f2\u3067\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\nuse Illuminate\\Support\\Str;\n\nclass <strong>IpAddressRange<\/strong>\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>if(!Str::startsWith($request-&gt;ip(), '111.111.111.')) {<\/strong>\n\n<strong>            return redirect('\/');<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<h2>\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u3067\u8a31\u53ef\uff0f\u62d2\u5426<\/h2>\n<p>\u4f8b\u3048\u3070\u3001<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u306b<code>role<\/code>\uff08\u3064\u307e\u308a\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\uff09\u306e\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u3066\u3001\u3053\u308c\u304c<code>admin<\/code>\u3082\u3057\u304f\u306f<code>super_admin<\/code>\u306e\u5834\u5408\u3060\u3051\u30da\u30fc\u30b8\u95b2\u89a7\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\n\nclass AdminAuth\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>if(auth()-&gt;check()) {<\/strong>\n\n<strong>            $role = auth()-&gt;user()-&gt;role;<\/strong>\n\n<strong>            if(in_array($role, ['admin', 'super_admin'])) {<\/strong>\n\n<strong>                return $next($request);<\/strong>\n\n<strong>            }<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        abort(403, '\u7ba1\u7406\u8005\u6a29\u9650\u304c\u3042\u308a\u307e\u305b\u3093\u3002');<\/strong>\n    }\n}<\/pre>\n<h2>\u7279\u5b9a\u306e\u8a00\u8a9e\u306e\u307f\u8a31\u53ef\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u3042\u308b\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u304c\u65e5\u672c\u8a9e\u3060\u3051\u5bfe\u5fdc\u3057\u3066\u3044\u3066\u308b\u306e\u3067\u65e5\u672c\u8a9e\u304c\u7406\u89e3\u3067\u304d\u308b\u4eba\u305f\u3061\u3060\u3051\u306b\u30da\u30fc\u30b8\u8868\u793a\u3092\u3057\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\n\nclass OnlyJapanese\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>if(!in_array('ja', $request-&gt;getLanguages())) {<\/strong>\n\n<strong>            abort(403);<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<p>\u203b \u305f\u3060\u3057\u3001\u8a00\u8a9e\u60c5\u5831\u306f\u30d6\u30e9\u30a6\u30b6\u306e\u30d8\u30c3\u30c0\u30fc\u3092\u5143\u306b\u3057\u3066\u53d6\u5f97\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306e\u6c17\u306b\u306a\u308c\u3070\u30d6\u30e9\u30a6\u30b6\u8a2d\u5b9a\u3067\u3044\u304f\u3089\u3067\u3082\u5909\u66f4\u306f\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u30b9\u30de\u30db\u306e\u5834\u5408\u306f\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u3042\u308b\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306b\u306f\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u5c02\u7528\u306e\u30da\u30fc\u30b8\u304c\u3042\u308a\u3001\u3082\u3057\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u3067\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304d\u305f\u5834\u5408\u306f\u305d\u3061\u3089\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u305b\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\n\nclass Smartphone\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>$detect = new \\Mobile_Detect();<\/strong>\n\n<strong>        if($detect-&gt;isMobile() || $detect-&gt;isTablet()) {<\/strong>\n\n<strong>            return redirect('\/smartphone');<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<p>\u203b \u306a\u304a\u3001\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\uff08\u30bf\u30d6\u30ec\u30c3\u30c8\uff09\u306e\u5224\u5225\u306f\u3001<a href=\"http:\/\/mobiledetect.net\/\">mobile detect<\/a>\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>composer require mobiledetect\/mobiledetectlib<\/strong><\/pre>\n<h2>\u7279\u5b9a\u306e\u56fd\u304b\u3089\u3060\u3051\u8a31\u53ef<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u65e5\u672c\u56fd\u5185\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306e\u307f\u3092\u8a31\u53ef\u3059\u308b\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\n\nclass OnlyInJapan\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>$geo = unserialize(<\/strong>\n<strong>            file_get_contents('http:\/\/www.geoplugin.net\/php.gp?ip='. $request-&gt;ip())<\/strong>\n<strong>        );<\/strong>\n\n<strong>        if($geo['geoplugin_countryCode'] !== 'JP') {<\/strong>\n\n<strong>            abort(403);<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<p>\u203b \u305f\u3060\u3057\u3001\u3053\u306e\u65b9\u6cd5\u306f<a href=\"https:\/\/www.geoplugin.com\/webservices\/php\" target=\"_blank\" rel=\"noopener noreferrer\">geoplugin.com<\/a>\u3068\u3044\u3046\u30b5\u30a4\u30c8\u306eAPI\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u30da\u30fc\u30b8\u306e\u8868\u793a\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u305d\u306e\u305f\u3081\u3001\u3082\u3057\u53ef\u80fd\u3067\u3042\u308c\u3070<code>nginx<\/code>\u306a\u3069\u3067IP\u3092\u7bc4\u56f2\u3067\u8a31\u53ef\u3059\u308b\u306a\u3069\u306e\u65b9\u304c\u3044\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\uff09<\/p>\n<h2>\u7279\u5b9a\u306e\u66dc\u65e5\u306e\u307f\u8868\u793a\u3092\u8a31\u53ef\u3059\u308b<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u6c34\u66dc\u65e5\u3060\u3051\u5546\u54c1\u304c\u5272\u5f15\u306b\u306a\u308b\u7533\u3057\u8fbc\u307f\u30da\u30fc\u30b8\u3092\u4f5c\u308a\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Carbon\\Carbon;\nuse Closure;\n\nclass OnlyWednesday\n{\n    public function handle($request, Closure $next)\n    {\n        <strong>$dt = new Carbon();<\/strong>\n\n<strong>        if($dt-&gt;dayOfWeek !== 3) {<\/strong>\n\n<strong>            abort('403', '\u6c34\u66dc\u65e5\u306e\u307f\u95b2\u89a7\u3067\u304d\u307e\u3059');<\/strong>\n\n<strong>        }<\/strong>\n\n<strong>        return $next($request);<\/strong>\n    }\n}<\/pre>\n<h1>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=3990&amp;tmstv=1777538045\" rel=\"nofollow\" id=\"download-link-3990\" data-redirect=\"false\" >\n\t\u3010Laravel 5.8 \u3011\u300c\u3053\u3093\u306a\u3068\u304d\u300d\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u5168\uff17\u5b9f\u4f8b<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u300c\u3053\u3093\u306a\u3068\u304d\u300d\u306b\u7126\u70b9\u3092\u3042\u3066\u3066\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306e\u7d39\u4ecb\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u4f7f\u3044\u65b9\u306b\u3088\u3063\u3066\u306f\u3088\u308a\u69d8\u3005\u306a\u5236\u9650\u3084\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u307f\u306a\u3055\u3093\u3082\u3044\u308d\u3044\u308d\u8a66\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-461 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/38.png\" alt=\"\" width=\"294\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/38.png 294w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/38-276x300.png 276w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/>\u300c\u30af\u30e9\u30d5\u30c8\u30d3\u30fc\u30eb\u3063\u3066\u7f8e\u5473\u3057\u3044\u3067\u3059\u306d\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u304cLaravel\u3092\u4f7f\u3044\u59cb\u3081\u305f\u306e\u306f\u30d0\u30fc\u30b8\u30e7\u30f34.2\u304c\u51fa\u3066\u3059\u3050\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u73fe\u5728\u306f\u3059\u3067\u306b\u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\u304c5.8\u306b\u306a\u308a\u3001\u3061\u3089\u307b\u30895.9\u306e\u8a71\u984c\u3082\u30cb\u30e5\u30fc\u30b9\u3068 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=3987\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010Laravel 5.8 \u3011\u300c\u3053\u3093\u306a\u3068\u304d\u300d\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u5168\uff17\u5b9f\u4f8b\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":3996,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[155],"class_list":["post-3987","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-155"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3987","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=3987"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3987\/revisions"}],"predecessor-version":[{"id":3997,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3987\/revisions\/3997"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/3996"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}