{"id":3519,"date":"2019-04-17T02:01:56","date_gmt":"2019-04-16T17:01:56","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=3519"},"modified":"2019-04-17T02:01:56","modified_gmt":"2019-04-16T17:01:56","slug":"laravel%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%8b%95%e7%94%bb%e9%85%8d%e4%bf%a1%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95%ef%bc%88%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89%e5%8f%af%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=3519","title":{"rendered":"Laravel\u3092\u4f7f\u3063\u3066\u52d5\u753b\u914d\u4fe1\u3059\u308b\u65b9\u6cd5\uff08\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3059\u3067\u306b\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u304c\u30de\u30eb\u30c1\u30e1\u30c7\u30a3\u30a2\u5316\u3057\u3066\u304b\u3089\u76f8\u5f53\u6642\u9593\u304c\u7d4c\u3061\u3001\u5f53\u6642\u306f\u307e\u3060\u73cd\u3057\u304b\u3063\u305f\uff08\u307e\u305f\u3001\u8996\u8074\u306b\u30b9\u30c8\u30ec\u30b9\u304c\u9ad8\u304b\u3063\u305f\ud83d\ude05\uff09\u52d5\u753b\u306e\u5b58\u5728\u306f\u306a\u304f\u3066\u306f\u306a\u3089\u306a\u3044\u3082\u306e\u3068\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u52d5\u753b\u306f\u3044\u307e\u3084\u8ab0\u3067\u3082\u6301\u3063\u3066\u3044\u308b\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u4ed8\u5c5e\u306e\u30ab\u30e1\u30e9\u3067\u3044\u3064\u3067\u3082\u64ae\u5f71\u304c\u3067\u304d\u308b\u305f\u3081\u3001\u64ae\u5f71\u3057\u305f\u3082\u306e\u3092\u500b\u5225\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30a6\u30a7\u30d6\u30b5\u30fc\u30d3\u30b9\u3082\u73cd\u3057\u3044\u3082\u306e\u3067\u306f\u306a\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306bLaravel\u3067\u6700\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u52d5\u753b\u3092\u914d\u4fe1\u3059\u308b\u65b9\u6cd5\u306f\uff1f\u3068\u3044\u3046\u3068\u3001<code>public<\/code>\u30d5\u30a9\u30eb\u30c0\u306b\u52d5\u753b\u3092\u8a2d\u7f6e\u3057\u76f4\u63a5\u30a6\u30a7\u30d6\u30b5\u30fc\u30d0\u30fc\u3092\u901a\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3059\u308c\u3070\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u3053\u3053\u3067\u3042\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u3068\u306a\u308b\u3068\uff11\u624b\u9593\u5fc5\u8981\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002\u305d\u308c\u304c\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u8a31\u53ef\u3055\u308c\u305f\u30e6\u30fc\u30b6\u30fc\u3060\u3051\u306b\u52d5\u753b\u3092\u516c\u958b\u3059\u308b<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u5148\u307b\u3069\u66f8\u3044\u305f<code>public<\/code>\u30d5\u30a9\u30eb\u30c0\u306b\u5165\u308c\u3066\u3057\u307e\u3046\u3068\u8ab0\u3067\u3082\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u305d\u3046\u3067\u306f\u306a\u304f\u4f8b\u3048\u3070\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3060\u3051\u304c\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u5236\u9650\u3092\u304b\u3051\u305f\u3044\u5834\u5408\u3067\u3059\u3002\u3057\u304b\u3082\u3001\u52d5\u753b\u30c7\u30fc\u30bf\u304c\u5168\u3066\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u3066\u304b\u3089\u3057\u304b\u518d\u751f\u3055\u308c\u306a\u3044\u3068\u306a\u308b\u3068\u4e0d\u4fbf\u3067\u3057\u3087\u3046\u304c\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3001\u5c11\u3057\u305a\u3064\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u53d6\u5f97\u3057\u306a\u304c\u3089\u518d\u751f\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306fLaravel\u3092\u4f7f\u3063\u3066<strong>\u5236\u9650\u3064\u304d\u52d5\u753b\u516c\u958b\u306e\u65b9\u6cd5<\/strong>\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u305f\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u3002\uff08\u6700\u5f8c\u306b\u4eca\u56de\u4f7f\u7528\u3057\u305f\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\uff09<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2173 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png\" alt=\"\" width=\"300\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24-281x300.png 281w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u958b\u767a\u74b0\u5883\uff1a Laravel 5.8<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u6b21\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>Laravel\u8a8d\u8a3c\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3060\u3051\u304c\u52d5\u753b\u3092\u518d\u751f\u3067\u304d\u308b<\/li>\n<li>\u52d5\u753b\u30c7\u30fc\u30bf\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u5b8c\u4e86\u3057\u3066\u3044\u306a\u304f\u3066\u3082\u518d\u751f\u304c\u3067\u304d\u308b<\/li>\n<\/ul>\n<h1>\u5b9f\u73fe\u3059\u308b\u65b9\u6cd5<\/h1>\n<p>\u30b3\u30fc\u30c9\u3092\u898b\u305f\u3044\u5834\u5408\u306f<a href=\"#code\">\u52d5\u753b\u914d\u4fe1\u3059\u308b\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\u307e\u3067\u8aad\u307f\u98db\u3070\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u52d5\u753b\u3092Laravel\uff08PHP\uff09\u3067\u8aad\u307f\u51fa\u3057\u3066\u914d\u4fe1\u3059\u308b\u5834\u5408\u3001\u72b6\u6cc1\u306b\u3088\u3063\u3066\uff12\u3064\u306e\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\uff11\u3064\u3081\u306f\u3001\u6700\u521d\u304b\u3089\u518d\u751f\u3059\u308b\uff08\u521d\u3081\u3066\u305d\u306e\u52d5\u753b\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304d\u305f\uff09\u5834\u5408\u3002\u3053\u306e\u5834\u5408\u306f\u305d\u306e\u52d5\u753b\u5168\u4f53\u3092\u914d\u4fe1\u3059\u308b\u3060\u3051\u3067\u3059\u306e\u3067\u3001Laravel\u3092\u4f7f\u3048\u3070\u305d\u308c\u307b\u3069\u96e3\u3057\u3044\u51e6\u7406\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\uff12\u3064\u76ee\u306f\u9014\u4e2d\u304b\u3089\u518d\u751f\u3059\u308b\u5834\u5408\u3067\u3059\u3002\u3053\u306e\u5834\u5408\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u5834\u6240\u304b\u3089\u518d\u751f\u3055\u308c\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u308f\u3051\u3067\u3059\u304b\u3089\u3001\u30d8\u30c3\u30c0\u30fc\u90e8\u5206\u306b\u305d\u308c\u76f8\u5fdc\u306e\u60c5\u5831\u3092\u683c\u7d0d\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1 id=\"code\">\u52d5\u753b\u914d\u4fe1\u3059\u308b\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/h1>\n<h2>\u57fa\u672c\u7684\u306a\u6e96\u5099<\/h2>\n<p>\u203b \u524d\u63d0\u3068\u3057\u3066<code>php artisan make:auth<\/code>\u3067Laravel\u8a8d\u8a3c\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002\u3082\u3057\u3001\u307e\u3060\u5b9f\u65bd\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u306f<a href=\"https:\/\/blog.capilano-fw.com\/?p=289\">\u3010Laravel5.6\u3011\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u76f4\u5f8c\u306b\u3084\u308b\u3053\u3068\uff13\u70b9<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u307e\u305aLaravel\u306b\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3068\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\uff08\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\uff09<\/strong><\/p>\n<pre><strong>Route::get('video\/stream', 'VideoController@stream');<\/strong><\/pre>\n<p><strong>\uff08\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\uff09<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Illuminate\\Http\\Request;\r\n\r\nclass VideoController extends Controller\r\n{\r\n    <strong>public function stream(Request $request) {<\/strong>\r\n\r\n<strong>        \/\/ \u3053\u3053\u306b\u52d5\u753b\u914d\u4fe1\u30b3\u30fc\u30c9\u3092\u66f8\u304f<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u91cd\u8981\u3068\u306a\u308b\u6a5f\u80fd\u300c\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u305f\u3089\u52d5\u753b\u518d\u751fOK\u300d\u3068\u3044\u3046\u90e8\u5206\u3092<code>middleware<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p>\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u306f\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u4e2d\u3067\u3082\u6307\u5b9a\u3067\u304d\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304b\u3089\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre>class VideoController extends Controller\r\n{\r\n    <strong>public function __construct() {\r\n\r\n        $this-&gt;middleware('auth');\r\n\r\n    }<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001<code>https:\/\/*****.com\/video\/stream<\/code>\u306b\u30ed\u30b0\u30a4\u30f3\u305b\u305a\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3521\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/laravel_login_form.png\" alt=\"\" width=\"757\" height=\"297\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/laravel_login_form.png 757w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/laravel_login_form-300x118.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/p>\n<h2>\u52d5\u753b\u914d\u4fe1\u306e\u90e8\u5206\u3092\u4f5c\u3063\u3066\u3044\u304f<\/h2>\n<p>\u3067\u306f\u3001\u3053\u3053\u304b\u3089\u304c\u30e1\u30a4\u30f3\u3068\u306a\u308b\u52d5\u753b\u30c7\u30fc\u30bf\u306e\u914d\u4fe1\u90e8\u5206\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u30b3\u30fc\u30c9\u304b\u3089\u3002<br \/>\n\u3061\u306a\u307f\u306b\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u306a\u306e\u3067\u3001<code>video\/test.mp4<\/code>\u3068\u3044\u3046\u52d5\u753b\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre>public function stream(Request $request) {\r\n\r\n    <strong>$path = storage_path('video\/test.mp4');<\/strong>\r\n\r\n<strong>    $file_size = filesize($path);<\/strong>\r\n<strong>    $fp = fopen($path, 'rb');<\/strong>\r\n<strong>    $status_code = 200;<\/strong>\r\n<strong>    $headers = [<\/strong>\r\n<strong>        'Content-type' =&gt; 'video\/mp4',<\/strong>\r\n<strong>        'Accept-Ranges' =&gt; 'bytes',<\/strong>\r\n<strong>        'Content-Length' =&gt; $file_size<\/strong>\r\n<strong>    ];<\/strong>\r\n\r\n<strong>    $range = $request-&gt;header('Range');<\/strong>\r\n\r\n<strong>    if(!is_null($range)) {<\/strong>\r\n\r\n<strong>        if(preg_match('|bytes=([0-9]+)\\-|', $range, $matches)) {<\/strong>\r\n\r\n<strong>            $start = intval($matches[1]);<\/strong>\r\n\r\n<strong>            if(fseek($fp, $start) === 0) {<\/strong>\r\n\r\n<strong>                $status_code = 206;<\/strong>\r\n<strong>                $headers['Content-Length'] = $file_size - $start;<\/strong>\r\n<strong>                $headers['Content-Range'] = sprintf(<\/strong>\r\n<strong>                    'bytes %d-%d\/%d',<\/strong>\r\n<strong>                    $start,<\/strong>\r\n<strong>                    ($file_size-1),<\/strong>\r\n<strong>                    $file_size<\/strong>\r\n<strong>                );<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>    return response()-&gt;stream(function() use($fp) {<\/strong>\r\n\r\n<strong>        fpassthru($fp);<\/strong>\r\n\r\n<strong>    }, $status_code, $headers);<\/strong>\r\n\r\n}<\/pre>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u307e\u305a\u518d\u751f\u3057\u305f\u3044\u52d5\u753b\u3067<code>fopen()<\/code>\u3067\u958b\u304d\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u30b5\u30a4\u30ba\u3084\u57fa\u672c\u3068\u306a\u308b\u30ec\u30b9\u30dd\u30f3\u30b9\u30fb\u30d8\u30c3\u30c0\u30fc\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u91cd\u8981\u306a\u306e\u304c<code>$request-&gt;header('Range');<\/code>\u306e\u90e8\u5206\u3067\u3059\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u3053\u306e\u90e8\u5206\u3067\u306f\u30d6\u30e9\u30a6\u30b6\u304c\u9001\u4fe1\u3057\u3066\u304d\u305f\u300cRange\u300d\u3068\u3044\u3046\u540d\u524d\u306e\u30d8\u30c3\u30c0\u30fc\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u3082\u3057\u3053\u3053\u304c<code>null<\/code>\u3067\u306f\u306a\u3044\u5834\u5408\u306f\u3001\u300c\u9014\u4e2d\u304b\u3089\u30c7\u30fc\u30bf\u3092\u304f\u3060\u3055\u3044\u300d\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u8fd4\u3059\u52d5\u753b\u30c7\u30fc\u30bf\u3082\u305d\u308c\u306b\u5408\u308f\u305b\u3066\u5909\u66f4\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3002<\/span><\/p>\n<p>\u305d\u3053\u3067<code>if<\/code>\u6587\u3067\u30c1\u30a7\u30c3\u30af\u3092\u3057\u3001\u3082\u3057\u52d5\u753b\u3092\u90e8\u5206\u7684\u306b\u8981\u6c42\u3059\u308b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u30de\u30c3\u30c1\u3057\u3066\u3044\u305f\u3089\u3001\u4ee5\u4e0b\uff12\u3064\u306e\u30d8\u30c3\u30c0\u30fc\u3092\u7528\u610f\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li><strong>Content-Length<\/strong>\u3000\u30fb\u30fb\u30fb\u3000\u30c7\u30fc\u30bf\u306e\u9577\u3055\uff08\u3064\u307e\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba &#8211; \u958b\u59cb\u4f4d\u7f6e\uff09<\/li>\n<li><strong>Content-Range<\/strong>\u3000\u30fb\u30fb\u30fb\u3000\u30c7\u30fc\u30bf\u306e\u7bc4\u56f2\uff08\u958b\u59cb\u4f4d\u7f6e\u3001\u7d42\u4e86\u4f4d\u7f6e\u3001\u30d5\u30eb\u306e\u9577\u3055\uff09\u304c\u5206\u304b\u308b\u30c7\u30fc\u30bf<\/li>\n<\/ul>\n<p>\u305d\u3057\u3066\u3001\u6700\u7d42\u7684\u306bLaravel\u306e<code>response()-&gt;stream()<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u901a\u3057\u3066PHP\u6a19\u6e96\u95a2\u6570\u306e<code>fpassthru()<\/code>\u3092\u5b9f\u884c\u3059\u308c\u3070\u5b8c\u6210\u3067\u3059\u3002<\/p>\n<p>\u203b \u3061\u306a\u307f\u306b\u30d8\u30c3\u30c0\u30fc\u60c5\u5831\u306e<code>Content-type-type<\/code>\u306f\u4eca\u56de\u56fa\u5b9a\u3067\u300cvideo\/mp4\u300d\u306b\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u52d5\u753b\u306b\u3088\u3063\u3066\u5207\u308a\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p>\u3082\u3057\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u672c\u4eba\u3060\u3051\u52d5\u753b\u3092\u518d\u751f\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u5834\u5408\u306f<code>Gate<\/code>\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002\u5b9f\u969b\u306b\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001<code>app\/Providers\/AuthServiceProvider.php<\/code>\u3092\u958b\u3044\u3066<code>boot()<\/code>\u5185\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>public function boot()\r\n{\r\n    $this-&gt;registerPolicies();\r\n\r\n    \/\/\r\n\r\n    <strong>\\Gate::define('play-video', function ($user, $video) {<\/strong>\r\n\r\n<strong>        return ($user-&gt;id === $video-&gt;user_id);<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u969b\u306bDB\u306b\u4fdd\u5b58\u3055\u308c\u305f\u30e6\u30fc\u30b6\u30fcID\u3068\u3001\u73fe\u5728\u30ed\u30b0\u30a4\u30f3\u4e2d\u306e\u30e6\u30fc\u30b6\u30fcID\u304c\u4e00\u81f4\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b<code>Gate<\/code>\u3067\u3059\u3002\uff08\u3064\u307e\u308a\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u4eba\u304b\u3069\u3046\u304b\u306e\u30c1\u30a7\u30c3\u30af\u3067\u3059\u306d\uff09<\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e<code>Gate<\/code>\u3092\u4f7f\u3046\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>public function stream(Request $request) {<\/strong>\r\n\r\n<strong>    $video = \\App\\Video::first();<\/strong>\r\n\r\n<strong>    if (\\Gate::allows('play-video', $video)) {<\/strong>\r\n\r\n        \/\/ \u3053\u3053\u3067\u3055\u3063\u304d\u306e\u52d5\u753b\u914d\u4fe1\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\r\n\r\n<strong>    }<\/strong><\/pre>\n<p>\u4ee5\u4e0a\u3067\u3059\uff01<\/p>\n<h1>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u6b21\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=3527&amp;tmstv=1777528687\" rel=\"nofollow\" id=\"download-link-3527\" data-redirect=\"false\" >\n\tLaravel\u3092\u4f7f\u3063\u3066\u52d5\u753b\u914d\u4fe1\u3059\u308b<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306fLaravel\u3067\u52d5\u753b\u3092\u914d\u4fe1\u3059\u308b\u65b9\u6cd5\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306e\u65b9\u6cd5\u3092\u4f7f\u3048\u3070\u3001\u30b5\u30a4\u30c8\u306b\u52d5\u753b\u914d\u4fe1\u3059\u308b\u6a5f\u80fd\u3092\u30d5\u30ec\u30ad\u30b7\u30d6\u30eb\u306b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u5f53\u7136\u3067\u3059\u304c\u52d5\u753b\u30d5\u30a1\u30a4\u30eb\u3068\u3044\u3046\u306e\u306f\u753b\u50cf\u3084\u30c6\u30ad\u30b9\u30c8\u3068\u6bd4\u3079\u3066\u305a\u3044\u3076\u3093\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5927\u304d\u3044\u3053\u3068\u304c\u5e38\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u30b5\u30fc\u30d0\u30fc\u74b0\u5883\u306b\u3088\u3063\u3066\u306f<code>ffmpeg<\/code>\u306a\u3069\u3067\u52d5\u753b\u3092\u5c0f\u3055\u304f\u5909\u63db\u3057\u305f\u308a\u3001\u5916\u90e8\u30b9\u30c8\u30ec\u30fc\u30b8\u306b\u4fdd\u5b58\u3057\u3066\u304a\u304f\u306a\u3069\u306e\u5de5\u592b\u3092\u3057\u306a\u3044\u3068\u30b5\u30fc\u30d0\u30fc\u304c\u983b\u7e41\u306b\u30c0\u30a6\u30f3\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u306b\u306a\u308a\u304b\u306d\u307e\u305b\u3093\u306e\u3067\u6c17\u3092\u3064\u3051\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u3053\u3053\u307e\u3067\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\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\u3001\u3059\u3067\u306b\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u304c\u30de\u30eb\u30c1\u30e1\u30c7\u30a3\u30a2\u5316\u3057\u3066\u304b\u3089\u76f8\u5f53\u6642\u9593\u304c\u7d4c\u3061\u3001\u5f53\u6642\u306f\u307e\u3060\u73cd\u3057\u304b\u3063\u305f\uff08\u307e\u305f\u3001\u8996\u8074\u306b\u30b9\u30c8\u30ec\u30b9\u304c\u9ad8\u304b\u3063\u305f\ud83d\ude05\uff09\u52d5\u753b\u306e\u5b58\u5728\u306f\u306a\u304f\u3066\u306f\u306a\u3089\u306a\u3044\u3082\u306e &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=3519\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel\u3092\u4f7f\u3063\u3066\u52d5\u753b\u914d\u4fe1\u3059\u308b\u65b9\u6cd5\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":3525,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,97],"tags":[138],"class_list":["post-3519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-97","tag-138"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3519","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=3519"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3519\/revisions"}],"predecessor-version":[{"id":3530,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/3519\/revisions\/3530"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/3525"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}