{"id":8714,"date":"2020-05-01T10:00:30","date_gmt":"2020-05-01T01:00:30","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8714"},"modified":"2020-04-30T17:25:06","modified_gmt":"2020-04-30T08:25:06","slug":"laravel%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e6%a9%9f%e8%83%bd%e3%81%ae%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8714","title":{"rendered":"[Laravel]\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306e\u4f7f\u7528"},"content":{"rendered":"\n<p>\u4eca\u56de\u306fLaravel\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u6a19\u6e96\u642d\u8f09\u3055\u308c\u3066\u3044\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u306e\u8aac\u660e\u3092\u304a\u3053\u306a\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h4>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u306e\u8a2d\u5b9a<\/h4>\n\n\n\n<p>Laravel\u3067\u306f\u5404\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u5fdc\u3057\u305fModel\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u304c\u3001Model\u30af\u30e9\u30b9\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30eb\u30fc\u30eb\u306e\u8ffd\u52a0\u3092\u304a\u3053\u306a\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3068\u3057\u3066\u3001students\u30c6\u30fc\u30d6\u30eb\u304c\u3042\u308b\u5834\u5408\u3001\u5bfe\u5fdc\u3059\u308bModel\u3068\u3057\u3066\u300cStudent\u300d\u30af\u30e9\u30b9\u306e\u4f5c\u6210\u3092\u304a\u3053\u306a\u3044\u307e\u3059\u3002<br> \u305d\u306e\u4e2d\u306bstatic\u3068\u3057\u3066\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u3092$rules\u306b\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Student extends Model{\n    public static $rules = [\n\t    'name'=>'required|string|max:20'\n\t\t'student_number'=>'integer|min:0'\n\t\t'team'=>'required|in:\u7d05\u7d44,\u767d\u7d44'\n\t];\n}<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u4f8b\u306e\u3088\u3046\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u300c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u5bfe\u8c61\u306eName =&gt; \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u300d\u3068\u3057\u3066\u914d\u5217\u3067\u8a18\u8ff0\u3057\u307e\u3059\u3002\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u304c\u8907\u6570\u3042\u308b\u5834\u5408\u306f\u300c|\u300d\u3067\u533a\u5207\u3063\u3066\u3001\u8907\u6570\u914d\u7f6e\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u307e\u305f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u3068\u3057\u3066\u5f15\u6570\u3092\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3082\u306e\u306f\u300c:\u300d\u4ee5\u964d\u3067\u6307\u5b9a\u3092\u304a\u3053\u306a\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4e0a\u8a18\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u8a2d\u5b9a\u3057\u305f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u306e\u610f\u5473\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>required<\/td><td>\u5fc5\u9808\u9805\u76ee<\/td><\/tr><tr><td>string<\/td><td>\u6587\u5b57\u5217<\/td><\/tr><tr><td>integer<\/td><td>\u6574\u6570\u5024<\/td><\/tr><tr><td>max<\/td><td>\u6700\u5927\u6841\u6570<\/td><\/tr><tr><td>min<\/td><td>\u6700\u5c0f\u6841\u6570<\/td><\/tr><tr><td>in<\/td><td>\u9078\u629e\u5019\u88dc\u306e\u3044\u305a\u308c\u304b\u3067\u3042\u308b\u3053\u3068<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h4>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30eb\u30fc\u30eb\u3092\u30d5\u30a9\u30fc\u30e0\u306b\u9069\u7528\u3059\u308b\u65b9\u6cd5<\/h4>\n\n\n\n<p>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b\u306b\u306fController\u5074\u3067validate\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$this->validate($request,Student::$rules)<\/code><\/pre>\n\n\n\n<p>\u30d5\u30a9\u30fc\u30e0\u304b\u3089POST\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306f$request\u306b\u5165\u3063\u3066\u3044\u307e\u3059\u3002$request\u306e\u5185\u5bb9\u304c$rules\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3057\u3066\u3044\u308b\u304b\u7167\u5408\u3092\u304a\u3053\u306a\u3044\u3001OK\u3067\u3042\u308c\u3070\u3001$this-&gt;validate\u4ee5\u964d\u306e\u51e6\u7406\u3092\u304a\u3053\u306a\u3044\u307e\u3059\u3002NG\u306e\u5834\u5408\u3001\u30a8\u30e9\u30fc\u5185\u5bb9\u306e\u4fdd\u5b58\u3092\u304a\u3053\u306a\u3044\u30d5\u30a9\u30fc\u30e0\u306e\u518d\u63cf\u753b\u304c\u304a\u3053\u306a\u308f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>$this-&gt;validate\u3067\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc\u5185\u5bb9\u306f\u5909\u6570$errors\u306e\u4e2d\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u3053\u306e\u5185\u5bb9\u3092\u30d5\u30a9\u30fc\u30e0(Blade\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8)\u306b\u8868\u793a\u3059\u308b\u3088\u3046\u306a\u51e6\u7406\u306e\u8a18\u8ff0\u3092\u304a\u3053\u306a\u3046\u3053\u3068\u306b\u3088\u308aHTML\u753b\u9762\u4e0a\u306b\u30a8\u30e9\u30fc\u6587\u8a00\u306e\u8868\u793a\u3092\u304a\u3053\u306a\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@if(count($errors) > 0) \n\u3000&lt;ul>\n  @foreach($errors->all() as $error) \n  &lt;li>{{ $error }}&lt;\/li> \n  @endforeach\n  &lt;\/ul>\n@endif<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u4f8b\u3067\u306f$errors\u5909\u6570\u5185\u306b\u30a8\u30e9\u30fc\u304c\u3072\u3068\u3064\u4ee5\u4e0a\u3042\u308b\u5834\u5408\u306b\u3001@foreach\u30eb\u30fc\u30d7\u3092\u304a\u3053\u306a\u3044\u3001\u30a8\u30e9\u30fc\u5185\u5bb9\u3092\u30ea\u30b9\u30c8\u5316\u3057\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u304cLaravel\u3067\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u4f7f\u7528\u65b9\u6cd5\u3067\u3059\u3002Laravel\u6a19\u6e96\u306e\u72b6\u614b\u3067\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306f\u82f1\u8a9e\u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u6b21\u56de\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u65e5\u672c\u8a9e\u5316\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u91d1\u66dc\u65e5\u62c5\u5f53\uff1anishida<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8714\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8714\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"[Laravel]\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306e\u4f7f\u7528\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8714\" data-text=\"[Laravel]\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306e\u4f7f\u7528\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8714\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8714\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fLaravel\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u6a19\u6e96\u642d\u8f09\u3055\u308c\u3066\u3044\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u306e\u8aac\u660e\u3092\u304a\u3053\u306a\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8714"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8714"}],"version-history":[{"count":12,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8714\/revisions"}],"predecessor-version":[{"id":8731,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8714\/revisions\/8731"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}