{"id":57,"date":"2017-06-08T17:25:09","date_gmt":"2017-06-08T08:25:09","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=57"},"modified":"2018-02-23T04:31:04","modified_gmt":"2018-02-22T19:31:04","slug":"laravel-%e3%81%a7%e8%a6%8b%e9%80%83%e3%81%97%e3%81%a6%e3%81%84%e3%81%9f%ef%bc%97%e3%81%a4%e3%81%ae%e4%be%bf%e5%88%a9%e6%a9%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=57","title":{"rendered":"Laravel \u3067\u898b\u9003\u3057\u3066\u3044\u305f\uff17\u3064\u306e\u4fbf\u5229\u6a5f\u80fd"},"content":{"rendered":"<p>\u79c1\u304c Laravel \u3092\u958b\u767a\u3067\u5229\u7528\u3057\u59cb\u3081\u305f\u306e\u306f\u30d0\u30fc\u30b8\u30e7\u30f3 4.2 \u304b\u3089\u3067\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u5f8c\u3082 Laravel \u306f\u9032\u5316\u3092\u7d9a\u3051\u3001\u300c\u3048\u3001\u3053\u3053\u307e\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u306e\uff01\uff1f\u300d\u3068\u3044\u3046\u30cb\u30e5\u30fc\u30b9\u3092\u9023\u767a\u3057\u3064\u3065\u3051\u3066\u304d\u305f\u3053\u3068\u306f\u6211\u3005\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u306f\u3068\u3066\u3082\u3042\u308a\u304c\u305f\u3044\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u305d\u306e\u6a5f\u80fd\u8ffd\u52a0\u304c\u901f\u3044\u3053\u3068\u3084\u591a\u3059\u304e\u308b\u305f\u3081\u6614\u304d\u3063\u3061\u308a\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u8aad\u3093\u3060\u9803\u304b\u3089\u3059\u308b\u3068\u3061\u3089\u307b\u3089\u300c\u898b\u843d\u3068\u3057\u3061\u3083\u3063\u3066\u308b\u3061\u3087\u3063\u3068\u3057\u305f\u4fbf\u5229\u6a5f\u80fd\u300d\u3068\u3044\u3046\u306e\u304c\u51fa\u3066\u304f\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u4eca\u56de\u306f\u300c\u3053\u308c\u3063\u3066\u3061\u3087\u3063\u3068\u4fbf\u5229\u3060\u3088\uff1f\u300d\u3068\u304a\u3059\u3059\u3081\u3057\u305f\u3044\u6a5f\u80fd\u3092\u72ec\u81ea\u306b\u307e\u3068\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\uff08\u72ec\u81ea\u3001\u3068\u3044\u3046\u3053\u3068\u306f\u307f\u3093\u306a\u306f\u300c\u305d\u308c\u3001\u5f53\u305f\u308a\u524d\u3060\u304b\u3089\uff01\u300d\u3082\u542b\u307e\u308c\u3066\u308b\u3063\u3066\u3053\u3068\u3067\u3059\uff08\u7b11\uff09\uff09<\/p>\n<p>\u3067\u306f\u3001\u65e9\u901f\u3044\u3063\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\uff11\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/routing\">Routing<\/a><\/p>\n<p>\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u6b63\u898f\u8868\u73fe\u3067\u5236\u9650\u3092\u304b\u3051\u3089\u308c\u308b\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u5165\u3063\u3066\u304f\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u5236\u9650\u3092\u304b\u3051\u3089\u308c\u308b\u306e\u3067\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u30d9\u30bf\u30fc\u306b\u306a\u308b\u304b\u3068\u3002<\/p>\n<pre>Route::get('sns\/{name}', function ($name) {\r\n    \/\/\r\n})-&gt;where('name', 'facebook|twitter|google-plus');<\/pre>\n<p>\u30b0\u30eb\u30fc\u30d7\u306b\u30c9\u30e1\u30a4\u30f3\u3092\u6307\u5b9a\u3067\u304d\u308b<br \/>\n\u3053\u308c\u5730\u5473\u306b\u4fbf\u5229\u3067\u3059\u3002\u3068\u3044\u3046\u306e\u3082\u30c6\u30b9\u30c8\u306a\u3069\u30ed\u30fc\u30ab\u30eb\u3060\u3051\u3067\u5b9f\u884c\u3057\u305f\u3044\u8a18\u8ff0\u3092\u3053\u3053\u306b\u3044\u308c\u3066\u304a\u3051\u3070\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3092\u5fd8\u308c\u3092\u3057\u3066\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3002<\/p>\n<pre>Route::group(['domain' =&gt; 'my-site.dev'], function () {\r\n    \/\/ Do something..\r\n});<\/pre>\n<p>\uff12\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/controllers\">Controller<\/a><\/p>\n<p>Restful API \u7528\u306e Controller \u304c\u30b3\u30de\u30f3\u30c9\u3067\u4e00\u767a\u4f5c\u6210\u3067\u304d\u308b\u3002<br \/>\n&#8211;resource \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u3064\u3051\u308b\u3060\u3051\u3067 GET, POST, PUT, DELETE \u306b\u5bfe\u5fdc\u3057\u305f Controller \u3092\u81ea\u52d5\u4f5c\u6210\u3057\u3066\u304f\u308c\u308b\u306a\u3093\u3066\u4fbf\u5229\u3059\u304e\u3067\u3059\u3002<\/p>\n<pre>php artisan make:controller PhotoController --resource<\/pre>\n<p>\u3057\u304b\u3082\u3001&#8211;model \u3092\u3064\u3051\u308c\u3070\u81ea\u52d5\u3067\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u307e\u3067\u3057\u3066\u304f\u308c\u3066\u3057\u307e\u3044\u307e\u3059\uff01\uff08\u30e2\u30c7\u30eb\u304c\u5b58\u5728\u3057\u306a\u3051\u308c\u3070\u300c\u4f5c\u308b\uff1f\u300d\u3068\u805e\u3044\u3066\u304d\u307e\u3059\uff09<\/p>\n<pre>php artisan make:controller PhotoController --resource --model=Photo<\/pre>\n<p>\u3055\u3089\u306b\u3055\u3089\u306b\u3001 Route \u306e\u65b9\u3067\u3082\u5168\u30da\u30fc\u30b8\u3092\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u306a\u306a\u304f\u3001\u305f\u3063\u305f\u4e00\u884c\u3067\uff2f\uff2b\uff01<\/p>\n<pre>Route::resource('photos', 'PhotoController');<\/pre>\n<p>\uff13\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/requests\">Request<\/a><\/p>\n<p>\u914d\u5217\u306f\u30c9\u30c3\u30c8\u3064\u306a\u304e\u3067\u3089\u304f\u3089\u304f\u53d6\u5f97\u3002<br \/>\n\u3082\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5165\u529b\u30dc\u30c3\u30af\u30b9\u304c\u3042\u3063\u3066\u9001\u4fe1\u3055\u308c\u305f\u3089\u3001<\/p>\n<pre>&lt;input name=\"products[0][name]\"&gt;\r\n&lt;input name=\"products[1][name]\"&gt;\r\n&lt;input name=\"products[2][name]\"&gt;<\/pre>\n<pre>$name = $request-&gt;input('products.0.name');  \/\/ \u4e00\u756a\u4e0a\u3060\u3051\u306e\u30c7\u30fc\u30bf\r\n$names = $request-&gt;input('products.*.name');  \/\/ \u540d\u524d\u3060\u3051\u306e\u914d\u5217<\/pre>\n<p>\u3068\u3044\u3046\u5f62\u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>fullurl() \u3067URL\u3092\u4e00\u767a\u53d6\u5f97<\/p>\n<p>\u904e\u53bb\u306b\u306f\u73fe\u5728\u306e URL \u3092\u53d6\u5f97\u3059\u308b\u306e\u306f\u3081\u3093\u3069\u3046\u3060\u3063\u305f\u8a18\u61b6\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u304c\u3042\u308c\u3070\u307e\u3055\u306b\u4e00\u767a\uff01\u3067\u3059\u306d\u3002<\/p>\n<pre>$url = $request-&gt;fullUrl();<\/pre>\n<p>storeAs() \u3067\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u3066\u4fdd\u5b58\u3067\u304d\u308b\u3002<br \/>\n\u3053\u306e\u8a18\u8ff0\u306e\u4ed5\u65b9\u3082\u30b7\u30f3\u30d7\u30eb\u3067\u3068\u3066\u3082\u7d20\u6674\u3089\u3057\u3044\u3067\u3059\u3002<\/p>\n<pre>$path = $request-&gt;photo-&gt;storeAs('images', 'filename.jpg');<\/pre>\n<p>\u306a\u304a\u3001Request \u304b\u3089\u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u30fc\u304c\u53d6\u5f97\u3067\u304d\u308b\u306e\u3082\u3068\u3066\u3082\u3044\u3044\u3067\u3059\u306d\u3002<\/p>\n<pre>$user = $request-&gt;user();<\/pre>\n<p>\uff14\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/helpers\">helpers<\/a><\/p>\n<p>old() \u30d8\u30eb\u30d1\u30fc\u3082\u30b7\u30f3\u30d7\u30eb\u3067\u4fbf\u5229\u3002<br \/>\n\u305f\u3063\u305f\uff13\u6587\u5b57\u306a\u306e\u3067\u53ef\u8aad\u6027\u304c\u9ad8\u3044\u3067\u3059\u3057\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3082\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3068\u304f\u306b Blade \u5185\u3067\u91cd\u5b9d\u3057\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<pre>$value = old('value');\r\n$value = old('value', 'default');<\/pre>\n<p>\uff15\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/validation\">Validation<\/a><\/p>\n<p>\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306e attribute name \u3092\u7c21\u5358\u306b\u8a2d\u5b9a\u3067\u304d\u308b\u3002<br \/>\nlang \u4ee5\u4e0b\u306e validation.php \u5185\u306b\u3042\u308b attributes \u3092\u8a2d\u5b9a\u3059\u308b\u3068\u81ea\u52d5\u3067\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u9069\u7528\u3055\u308c\u307e\u3059\u3002<br \/>\n\u3061\u306a\u307f\u306b\u65e5\u672c\u8a9e\u306e\u5834\u5408\u306f\u300cresources\/lang\/ja\/validation.php\u300d\u3067\u3059\u3002<\/p>\n<pre>'attributes' =&gt; [\r\n    'email' =&gt; '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9',\r\n],<\/pre>\n<p>\u203b\u57fa\u672c\u7684\u306a\u7ffb\u8a33\u30e1\u30c3\u30bb\u30fc\u30b8\u306f<a href=\"https:\/\/github.com\/caouecs\/Laravel-lang\/tree\/master\/src\/ja\">\u3053\u3053<\/a>\u304b\u3089\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u611f\u8b1d\uff01<\/p>\n<p>\uff16\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/blade\">Blade<\/a><\/p>\n<p>@foreach &#8230; @endforeach \u5185\u3067\u81ea\u52d5\u7684\u306b\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b $loop\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<pre>$loop-&gt;index; \/\/ \u30bc\u30ed\u304b\u3089\u59cb\u307e\u308b\u756a\u53f7\r\n$loop-&gt;iteration; \/\/ \uff11\u304b\u3089\u59cb\u307e\u308b\u756a\u53f7\uff08$i+1\u3059\u308b\u5fc5\u8981\u306a\u304b\u3063\u305f\uff01\uff09\r\n$loop-&gt;remaining; \/\/ \u6b8b\u308a\u306f\u3044\u304f\u3064\u304c\u5206\u304b\u308b\u6570\u5b57\u3002\r\n$loop-&gt;first; \/\/ \u4e00\u756a\u6700\u521d\u306e\u30c7\u30fc\u30bf\u3067\u3059\u304b\uff1f\r\n$loop-&gt;last; \/\/ \u4e00\u756a\u6700\u5f8c\u306e\u30c7\u30fc\u30bf\u3067\u3059\u304b\uff1f\u3053\u308c\u3092\u4f7f\u3048\u3070&lt;hr&gt;\u3067\u533a\u5207\u3063\u3066\u7c21\u5358\u306b\u6700\u5f8c\u3060\u3051\u8868\u793a\u3057\u306a\u3044\u3088\u3046\u306b\u3067\u304d\u307e\u3059\u306d\uff01<\/pre>\n<p>\u307e\u305f\u3001@php &#8230; @endphp \u3063\u3066\u3044\u3046\u304c\u3042\u308b\u306e\u3092\u77e5\u308a\u307e\u3057\u305f\u3002<br \/>\n\u3044\u3061\u3044\u3061 <!--?php?--> \u3092\u66f8\u304f\u5fc5\u8981\u306f\u306a\u304f\u306a\u308a\u307e\u3059\u3057\u3001\u7d71\u4e00\u611f\u304c\u3067\u308b\u306e\u3067\u3044\u3044\u3067\u3059\u306d\u3002<\/p>\n<pre>@php\r\n\r\n    \/\/ \u3053\u3053\u306f PHP \u30d7\u30ed\u30b0\u30e9\u30e0\r\n\r\n@endphp<\/pre>\n<p>\uff17\uff0e<a href=\"https:\/\/laravel.com\/docs\/5.4\/eloquent\">Eloquent<\/a><\/p>\n<p>\u30e2\u30c7\u30eb\u5185\u306b Notifiable \u30c8\u30ec\u30a4\u30c8\u3068 $events \u3092\u8a2d\u5b9a\u3059\u308b\u3060\u3051\u3067\u4ee5\u4e0b\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored<\/p>\n<pre>class User extends Authenticatable\r\n{\r\n    use Notifiable;\r\n    \r\n    \/**\r\n    * The event map for the model.\r\n    *\r\n    * @var array\r\n    *\/\r\n    protected $events = [\r\n        'saved' =&gt; UserSaved::class,\r\n        'deleted' =&gt; UserDeleted::class,\r\n    ];\r\n}<\/pre>\n<p>\u756a\u5916\u7de8\uff08<a href=\"https:\/\/laravel.com\/docs\/5.4\/views\">View<\/a>\uff09<\/p>\n<p>\u30d3\u30e5\u30fc\u5358\u4f4d\u3067\u7279\u5b9a\u30c7\u30fc\u30bf\u3092\u547c\u3073\u51fa\u305b\u308b\u3088\u3046\u306b\u306a\u308b <a href=\"https:\/\/laravel.com\/docs\/5.4\/views#view-composers\">ViewComposer<\/a>\u3002<br \/>\n\u9577\u304f\u306a\u308b\u306e\u3067\u8aac\u660e\u306f\u5272\u611b\u3057\u307e\u3059 m_ _m<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4ee5\u4e0a\u304c\uff17\u3064\u306e\u3061\u3087\u3063\u3068\u4fbf\u5229\u3060\u3088\u3001\u6a5f\u80fd\u3067\u3057\u305f\u3002<br \/>\n\u8208\u5473\u304c\u3042\u3063\u305f\u3089\u305c\u3072\u6d3b\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u79c1\u304c Laravel \u3092\u958b\u767a\u3067\u5229\u7528\u3057\u59cb\u3081\u305f\u306e\u306f\u30d0\u30fc\u30b8\u30e7\u30f3 4.2 \u304b\u3089\u3067\u3057\u305f\u3002 \u305d\u306e\u5f8c\u3082 Laravel \u306f\u9032\u5316\u3092\u7d9a\u3051\u3001\u300c\u3048\u3001\u3053\u3053\u307e\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u306e\uff01\uff1f\u300d\u3068\u3044\u3046 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=57\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel \u3067\u898b\u9003\u3057\u3066\u3044\u305f\uff17\u3064\u306e\u4fbf\u5229\u6a5f\u80fd&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":65,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[8],"class_list":["post-57","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-8"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/57","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=57"}],"version-history":[{"count":10,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":330,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions\/330"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/65"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}