{"id":2691,"date":"2026-07-09T18:50:26","date_gmt":"2026-07-09T09:50:26","guid":{"rendered":"http:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/?page_id=2691"},"modified":"2026-07-24T19:26:05","modified_gmt":"2026-07-24T10:26:05","slug":"laravel-03","status":"publish","type":"page","link":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/programming\/php\/laravel-03","title":{"rendered":"Laravel: \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4ecb\u3057\u305f\u30c7\u30fc\u30bf\u306e\u9001\u53d7\u4fe1"},"content":{"rendered":"<p>Laravel\u3092\u4f7f\u3063\u3066\u7814\u7a76\u5ba4\u306e\u6750\u6599\u30fb\u30b5\u30f3\u30d7\u30eb\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u3092\u958b\u767a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u524d\u56de\u306e\u7d42\u4e86\u6642\u70b9\u306e\u72b6\u614b\u3092\u518d\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"console\">\n$ git clone https:\/\/kiku3.tsbio.info\/git\/study-laravel.git study_laravel\n$ git checkout step2\n<\/pre>\n<p>\u4e00\u5ea6\u3053\u3053\u3067\u81ea\u5206\u306e\u30d6\u30e9\u30f3\u30c1\u3092\u3064\u304f\u3063\u3066\u304a\u304f\u3068\u3088\u3044\u3067\u3059\u3002<\/p>\n<pre class=\"console\">\n$ git checkout -b my2\n<\/pre>\n<p>\u4eca\u5f8c\u306f\u57fa\u672c\u7684\u306bsrc\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u4f5c\u696d\u3057\u307e\u3059\u3002VisualStudioCode\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001<code>code src<\/code>\u3068\u3059\u308b\u3068\u3088\u3044\u3067\u3059\u3002<\/p>\n<h2>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc(controller)\u3092\u5c0e\u5165\u3059\u308b<\/h2>\n<p><\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u306e\u30ea\u30af\u30a8\u30b9\u30c8(URL\u3084\u9001\u4fe1\u30c7\u30fc\u30bf)\u306b\u5fdc\u3058\u3066\u3001\u30d3\u30e5\u30fc\u3092\u8fd4\u3059\u524d\u306b\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u7684\u306a\u51e6\u7406\u3092\u884c\u3046\u305f\u3081\u306b\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u9593\u306b\u3044\u308c\u307e\u3059\u3002\nroute &#8211; controller &#8211; view \u3068\u3044\u3046\u6d41\u308c\u3067PHP\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u9806\u6b21\u5b9f\u884c\u3055\u308c\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>controller\u306f <code>app\/Http\/Controllers\/<\/code> \u4ee5\u4e0b\u306b\u7f6e\u304d\u307e\u3059\u3002\nartisan\u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u3068\u304d\u306f .\/artisan make:controller controller_name \u3068\u3059\u308b\u3053\u3068\u3067\u30d5\u30a1\u30a4\u30eb\u304c\u3067\u304d\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u7279\u5b9a\u306e\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u306e\u3067\u30010\u304b\u3089\u3064\u304f\u3063\u3066\u3044\u3063\u3066\u3082\u304b\u307e\u3044\u307e\u305b\u3093\u3002<\/p>\n<h3>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u7d4c\u7531\u3059\u308b\u3088\u3046\u306b\u30eb\u30fc\u30c8\u3092\u7de8\u96c6\u3059\u308b<\/h3>\n<p>\/oligo\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3092 OligoController\u306b\u56de\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002\n\u305d\u306e\u305f\u3081\u306b <code>routes\/web.php<\/code> \u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">routes\/web.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nuse Illuminate\\Support\\Facades\\Route;\nuse App\\Http\\Controllers\\OligoController;\n \n\/*\n *\t\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u7d4c\u7531\u3059\u308b\u30eb\u30fc\u30c8\n *\/\nRoute::prefix(&#039;\/oligo&#039;)-&gt;as(&#039;web.oligo.&#039;)-&gt;group(function (){\n    Route::get(&#039;\/&#039;, [OligoController::class, &#039;index&#039;])-&gt;name(&#039;index&#039;);\n    Route::get(&#039;\/create&#039;, [OligoController::class, &#039;create&#039;])-&gt;name(&#039;create&#039;);\n    Route::post(&#039;\/&#039;, [OligoController::class, &#039;store&#039;])-&gt;name(&#039;store&#039;);\n});\n<\/pre>\n<\/div>\n<p>get\u306e2\u756a\u76ee\u306e\u5f15\u6570\u304c action \u3067\u3001\u3053\u306e\u30eb\u30fc\u30c8\u304c\u9078\u3070\u308c\u305f\u5834\u5408\u306b\u5b9f\u884c\u3059\u308b\u95a2\u6570\u3092\u4e0e\u3048\u307e\u3059\u3002\n[\u30af\u30e9\u30b9\u540d, \u30e1\u30bd\u30c3\u30c9\u540d]\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u6307\u5b9a\u3059\u308b\u5f62\u3067\u3059\u3002<\/p>\n<p>\u6b21\u3044\u3067\u3001 <code>app\/Http\/Controllers\/OligoController.php<\/code> \u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">app\/Http\/Controllers\/OligoController.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nnamespace App\\Http\\Controllers;\n \nclass OligoController\n{\n    public function index(){\n        return view(&#039;oligo.index&#039;);\n    }\n \n    public function create(){\n        return view(&#039;oligo.create&#039;);\n    }\n}\n<\/pre>\n<\/div>\n<p>\/oligo \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068 OligoController \u306e index \u30e1\u30bd\u30c3\u30c9\u3092\u7d4c\u7531\u3057\u3066\u3001 view()\u304c\u8fd4\u308a\u3001\u3053\u308c\u307e\u3067\u3068\u540c\u3058\u753b\u9762\u304c\u30d6\u30e9\u30a6\u30b6\u30fc\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u30eb\u30fc\u30c8\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b<\/h3>\n<p>3\u3064\u306e\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\/oligo \u3078\u306e GET \u3067\u306e\u30a2\u30af\u30bb\u30b9\u306b\u5bfe\u3057\u3001\u4e00\u89a7\u3092\u8fd4\u3059\u30eb\u30fc\u30c8 (index)\u3002<\/li>\n<li>\/oligo\/create \u3078\u306e GET \u3067\u306e\u30a2\u30af\u30bb\u30b9\u306b\u5bfe\u3057\u3001\u30c7\u30fc\u30bf\u767b\u9332\u7528\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u8fd4\u3059\u30eb\u30fc\u30c8 (create)\u3002<\/li>\n<li>\/oligo \u3078\u65b0\u3057\u3044\u30aa\u30ea\u30b4DNA\u306e\u60c5\u5831\u304c POST \u3055\u308c\u305f\u3068\u304d\u3001\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3059\u308b\u30eb\u30fc\u30c8 (store)\u3002<\/li>\n<\/ul>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u7e70\u308a\u8fd4\u3057 Route::prefix \u306b \/oligo \u3092\u6e21\u3059\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u91cd\u8907\u3057\u305f\u8a2d\u5b9a\u3092\u7701\u304f\u305f\u3081\u306b\u3001\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u540c\u6642\u306b\u3001\u30eb\u30fc\u30c8\u306b\u540d\u524d\u3092\u3064\u3051\u307e\u3059\u3002\u540d\u524d\u3092\u3064\u3051\u308b\u3053\u3068\u306b\u3088\u3063\u3066laravel\u304c\u63d0\u4f9b\u3059\u308broute\u95a2\u6570\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u3001URL\u3092\u81ea\u52d5\u3067\u4f5c\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001.env\u306eAPP_URL\u304c\u5909\u308f\u3063\u305f\u3068\u304d\u3001\u3059\u306a\u308f\u3061\u958b\u767a\u74b0\u5883\u3068\u672c\u756a\u74b0\u5883\u3067\u306eURL\u306e\u9055\u3044\u3092\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u5909\u66f4\u306a\u304f\u5438\u53ce\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30eb\u30fc\u30c8\u306e\u540d\u524d\u306b\u3082\u968e\u5c64\u69cb\u9020\u3092\u3064\u3051\u308b\u305f\u3081\u3001as\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p><code>routes\/web.php<\/code> \u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">routes\/web.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nuse Illuminate\\Support\\Facades\\Route;\nuse App\\Http\\Controllers\\OligoController;\n \n\/*\n *\t\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u7d4c\u7531\u3059\u308b\u30eb\u30fc\u30c8\n *\/\nRoute::prefix(&#039;\/oligo&#039;)-&gt;as(&#039;web.oligo.&#039;)-&gt;group(function (){\n    Route::get(&#039;\/&#039;, [OligoController::class, &#039;index&#039;])-&gt;name(&#039;index&#039;);\n    Route::get(&#039;\/create&#039;, [OligoController::class, &#039;create&#039;])-&gt;name(&#039;create&#039;);\n    Route::post(&#039;\/&#039;, [OligoController::class, &#039;store&#039;])-&gt;name(&#039;store&#039;);\n});\n<\/pre>\n<\/div>\n<p>\u6b63\u3057\u304froute\u304c\u3067\u304d\u3066\u3044\u308b\u304b\u306f .\/artisan route:list \u3068\u3057\u3066\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre class='console'>\n# php artisan route:list\n\n  GET|HEAD  oligo .................. web.oligo.index \u203a OligoController@index\n  POST      oligo .................. web.oligo.store \u203a OligoController@store\n  GET|HEAD  oligo\/create ......... web.oligo.create \u203a OligoController@create\n<\/pre>\n<p>\u30ea\u30f3\u30af\u5148\u3092\u76f4\u63a5\u66f8\u304d\u8fbc\u3093\u3067\u3044\u305f <code>resources\/views\/oligo\/module.blade.php<\/code> \u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">resources\/views\/oligo\/module.blade.php<\/h5>\n    <pre class=\"code\">\n@extends(&#039;layouts.app&#039;)\n \n@section(&#039;module&#039;)\n  &lt;x-module id=&#039;oligo&#039;&gt;\n    &lt;!-- \u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e1\u30cb\u30e5\u30fc --&gt;\n    &lt;nav&gt;\n      &lt;ul class=&#039;module-tabs&#039; role=&#039;tablist&#039;&gt;\n        @foreach([\n          &#039;index&#039; =&gt; &#039;\u4e00\u89a7&#039;,\n          &#039;create&#039; =&gt; &#039;\u8ffd\u52a0&#039;,\n        ] as $page =&gt; $label)\n          &lt;li&gt;&lt;a href=&#039;{{ route(&quot;web.oligo.{$page}&quot;) }}&#039; id=&#039;oligo-{{ $page }}-tab&#039; role=&#039;tab&#039;&gt;{{ $label }}&lt;\/a&gt;&lt;\/li&gt;\n        @endforeach\n      &lt;\/ul&gt;\n    &lt;\/nav&gt;\n    \n    &lt;!-- feature\u304c\u4e26\u3076\u3068\u3053\u308d --&gt;\n    &lt;div class=&#039;features&#039;&gt;\n      @yield(&#039;feature&#039;)\n    &lt;\/div&gt;\n  &lt;\/x-module&gt;\n@endsection\n<\/pre>\n<\/div>\n<p>\u5408\u308f\u305b\u3066 app\/Http\/Controllers\/OligoController.php \u3082\u7de8\u96c6\u3057\u3001create\u3068store\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<h2>\u53d7\u4fe1\u3057\u305f\u30c7\u30fc\u30bf(\u30ea\u30af\u30a8\u30b9\u30c8)\u306e\u51e6\u7406<\/h2>\n<h3>\u30c7\u30fc\u30bf\u9001\u4fe1\u7528\u30d5\u30a9\u30fc\u30e0\u306e\u4f5c\u6210<\/h3>\n<p><\/p>\n<p>\u65b0\u3057\u3044\u30c7\u30fc\u30bf(\u30aa\u30ea\u30b4DNA)\u3092\u767b\u9332\u3059\u308b\u305f\u3081\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">resources\/views\/oligo\/create.blade.php<\/h5>\n    <pre class=\"code\">\n@extends(&#039;oligo.module&#039;)\n \n@section(&#039;feature&#039;)\n&lt;x-feature id=&#039;oligo-create&#039;&gt;\n  &lt;form action=&quot;{{ route(&#039;web.oligo.store&#039;) }}&quot; method=&quot;POST&quot;&gt;\n    @csrf\n    &lt;dl&gt;\n      &lt;dt&gt;\u540d\u524d&lt;\/dt&gt;\n      &lt;dd&gt;&lt;input type=&#039;text&#039; name=&#039;name&#039;&gt;&lt;\/dd&gt;\n      &lt;dt&gt;\u914d\u5217&lt;\/dt&gt;\n      &lt;dd&gt;&lt;input type=&#039;text&#039; name=&#039;sequence&#039;&gt;&lt;\/dd&gt;\n      &lt;dt&gt;\u4f5c\u6210\u65e5&lt;\/dt&gt;\n      &lt;dd&gt;&lt;input type=&#039;text&#039; name=&#039;updated_at&#039;&gt;&lt;\/dd&gt;\n      &lt;dt&gt;\u6240\u6709\u8005&lt;\/dt&gt;\n      &lt;dd&gt;&lt;input type=&#039;text&#039; name=&#039;owner&#039;&gt;&lt;\/dd&gt;\n      &lt;dt&gt;&lt;button type=&#039;submit&#039;&gt;\u767b\u9332&lt;\/button&gt;&lt;\/dt&gt;\n    &lt;\/dl&gt;\n  &lt;\/form&gt;\n&lt;\/x-feature&gt;\n@endsection\n<\/pre>\n<\/div>\n<p>3\u3064\u65b0\u3057\u3044blade\u306e\u4f7f\u3044\u65b9\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u30d5\u30a9\u30fc\u30e0\u306b\u3088\u308b\u9001\u4fe1\u5148(action\u5c5e\u6027)\u306b route\u95a2\u6570 \u3092\u4f7f\u3046\u3002\u3053\u3053\u3067\u6307\u5b9a\u3057\u3066\u3044\u308b web.oligo.store \u306f routes\/web.php \u3067\u8a2d\u5b9a\u3057\u305f\u30eb\u30fc\u30c8\u306b\u5bfe\u3059\u308b\u540d\u524d\u3067\u3001as\u3068name\u306b\u3088\u3063\u3066\u3001web.oligo.store \u3068\u3044\u3046\u6587\u5b57\u5217\u306b\u7d44\u307f\u7acb\u3066\u3089\u308c\u3066\u3044\u307e\u3059\u3002<\/li>\n<li>POST\u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408\u306f <input type=\"hidden\" name=\"_token\" value=\"\" autocomplete=\"off\"> \u3092form\u8981\u7d20\u306e\u3069\u3053\u304b\u306b\u66f8\u304f\u3002\u3053\u308c\u306f Cross-Site Request Forgeries \u3068\u3044\u3046\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u507d\u9020\u306b\u3088\u308b\u653b\u6483\u306b\u5bfe\u3059\u308b\u5bfe\u5fdc\u3067\u3059\u3002laravel\u306fCSRF\u653b\u6483\u306b\u5bfe\u3059\u308b\u9632\u5fa1\u3092\u81ea\u52d5\u7684\u306b\u884c\u3044\u307e\u3059\u3002<\/li>\n<li>__ (\u30a2\u30f3\u30c0\u30fc\u30d0\u30fc\u30922\u500b\u4e26\u3079\u305f\u3082\u306e)\u306f\u7ffb\u8a33\u3092\u884c\u3046\u95a2\u6570\u3067\u3059\u3002&#8217;\u767b\u9332&#8217;\u306b\u5bfe\u3059\u308b\u8a33\u8a9e\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u30d6\u30e9\u30a6\u30b6\u30fc\u306e\u8a00\u8a9e\u306b\u5408\u308f\u305b\u3066\u7ffb\u8a33\u3057\u3066\u304f\u308c\u307e\u3059(\u3069\u3053\u3067\u8a2d\u5b9a\u3059\u308b\u306e\u304b\u306f\u4eca\u5f8c\u63b2\u8f09\u4e88\u5b9a)\u3002<\/li>\n<\/ol>\n<p>\/oligo\/create\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306a\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<div class=\"browser-image\">\n\n      <header>\n    <h1>My Lab&#039;s Stock<\/h1>\n    <ul id='module-tabs'>\n      <li><a id='oligo-tab' href='\/oligo'>\u30aa\u30ea\u30b4DNA<\/a><\/li>\n    <\/ul>\n  <\/header>\n  <main id='modules'>\n      <div class='module-panel' id=\"$module\" role=\"tabpanel\">\n  <!-- \u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30e1\u30cb\u30e5\u30fc -->\n    <nav>\n      <ul class='module-tabs' role='tablist'>\n                  <li><a href='\/oligo\/index 'id='oligo-index-tab' role='tab'>\u4e00\u89a7<\/a><\/li>\n                  <li><a href='\/oligo\/create 'id='oligo-create-tab' role='tab'>\u8ffd\u52a0<\/a><\/li>\n              <\/ul>\n    <\/nav>\n    \n    <!-- feature\u304c\u4e26\u3076\u3068\u3053\u308d -->\n    <div class='features'>\n      <div class='feature-panel' id=\"oligo-create\">\n  <form action=\"http:\/\/localhost:8002\/oligo\" method=\"POST\">\n    <input type=\"hidden\" name=\"_token\" value=\"FSLRtGeiakkPXlQvNyOdrOsfjJxKfNMi9XuKrqJu\" autocomplete=\"off\">    <dl>\n      <dt>\u540d\u524d<\/dt>\n      <dd><input type='text' name='name'><\/dd>\n      <dt>\u914d\u5217<\/dt>\n      <dd><input type='text' name='sequence'><\/dd>\n      <dt>\u4f5c\u6210\u65e5<\/dt>\n      <dd><input type='text' name='updated_at'><\/dd>\n      <dt>\u6240\u6709\u8005<\/dt>\n      <dd><input type='text' name='owner'><\/dd>\n      <dt><button type='submit'>\u767b\u9332<\/button><\/dt>\n    <\/dl>\n  <\/form>\n<\/div>\n    <\/div>\n<\/div>\n  <\/main>\n\n<\/div>\n<p>\u307e\u3060 OligoController.php \u306bstore\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u9001\u4fe1\u3057\u3066\u3082\u4f55\u3082\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<h3>\u5165\u529b\u30c7\u30fc\u30bf\u306e\u691c\u8a3c<\/h3>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u9001\u3089\u308c\u3066\u304f\u308b\u30c7\u30fc\u30bf\u306f\u5fc5\u305a\u691c\u8a3c(validation)\u304c\u5fc5\u8981\u3067\u3059\u3002\n\u691c\u8a3c\u306f app\/Http\/Requests\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4ee5\u4e0b\u306b\u4f5c\u6210\u3059\u308b Request \u30af\u30e9\u30b9\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>Laravel\u3067\u306e\u5024\u306e\u691c\u8a3c\u65b9\u6cd5\u306f <a href=\"https:\/\/readouble.com\/laravel\/13.x\/ja\/validation.html\">https:\/\/readouble.com\/laravel\/13.x\/ja\/validation.html<\/a> \u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">app\/Http\/Requests\/OligoRequest.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nnamespace App\\Http\\Requests;\n \nuse Illuminate\\Contracts\\Validation\\ValidationRule;\nuse Illuminate\\Foundation\\Http\\FormRequest;\n \nclass OligoRequest extends FormRequest\n{\n    public function rules(): array\n    {\n        return [\n            &#039;name&#039; =&gt; [&#039;required&#039;, &#039;string&#039;, &#039;max:100&#039;],\n                \/\/ \u914d\u5217\u3067\u306f\u306a\u304f\u3001| \u3067\u533a\u5207\u3063\u3066\u6587\u5b57\u5217\u306b\u3057\u3066\u3082\u3088\u3044\u3002\n                \/\/ \u4f8b: &#039;required|string|max:100&#039; \n            &#039;sequence&#039; =&gt; [&#039;required&#039;, &#039;string&#039;, &#039;regex:\/^[A-Z]{6,255}$\/&#039;],\n            &#039;updated_at&#039; =&gt; [&#039;nullable&#039;, &#039;string&#039;, &#039;regex:\/^[0-9]{6}$\/&#039;],\n            &#039;owner&#039; =&gt; [&#039;nullable&#039;, &#039;string&#039;, &#039;max:100&#039;],\n        ];\n    }\n \n    \/*\n     *  \u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306f\u306a\u304f\u3066\u3082\u3088\u3044\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u4f7f\u308f\u308c\u308b\u3002\n     *\/\n    public function messages(): array\n    {\n        return [\n            &#039;name.max&#039; =&gt; &#039;\u30b5\u30f3\u30d7\u30eb\u540d\u306f255\u6587\u5b57\u4ee5\u5185\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&#039;,\n            &#039;sequence.regex&#039; =&gt; &#039;\u914d\u5217\u306f\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u5927\u6587\u5b57\u30676-255\u306e\u9577\u3055\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&#039;,\n            &#039;owner.max&#039; =&gt; &#039;\u6240\u6709\u8005\u306f100\u6587\u5b57\u4ee5\u5185\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002&#039;,\n        ];\n    }\n}\n<\/pre>\n<\/div>\n<ul>\n<li>\u30d5\u30a9\u30fc\u30e0\u304b\u3089\u9001\u4fe1\u3055\u308c\u3066\u304f\u308b\u30c7\u30fc\u30bf\u306f FormRequest\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u3067\u884c\u3044\u307e\u3059\u3002<\/li>\n<li>rules \u30e1\u30bd\u30c3\u30c9\u3067\u3001\u30d5\u30a3\u30fc\u30eb\u30c9\u540d(input\u30bf\u30b0\u306ename\u5c5e\u6027\u306e\u5024)\u3092\u30ad\u30fc\u306b\u3001\u305d\u308c\u306b\u9069\u7528\u3059\u308b\u30eb\u30fc\u30eb\u306e\u914d\u5217\u3092\u5024\u3068\u3059\u308b\u914d\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n<li>messages\u30e1\u30bd\u30c3\u30c9\u306f \u30d5\u30a3\u30fc\u30eb\u30c9\u540d.\u30eb\u30fc\u30eb\u540d \u3092\u30ad\u30fc\u306b\u3001\u5bfe\u5fdc\u3059\u308b\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5024\u3068\u3059\u308b\u914d\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5074\u3067\u306f\u3053\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u30af\u30e9\u30b9\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">app\/Http\/Controllers\/OligoController.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nnamespace App\\Http\\Controllers;\n \nuse App\\Http\\Requests\\OligoRequest;\n \nclass OligoController\n{\n    public function index(){\n        return view(&#039;oligo.index&#039;);\n    }\n \n    public function create(){\n        return view(&#039;oligo.create&#039;);\n    }\n \n    public function store(OligoRequest $request){\n        var_dump($request-&gt;validated());\n    }\n}\n<\/pre>\n<\/div>\n<p>$request-&gt;validated()\u3068\u3059\u308b\u3053\u3068\u3067\u3001\u691c\u8a3c\u6e08\u307f\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u691c\u8a3c\u5931\u6557\u6642\u306e\u51e6\u7406<\/h3>\n<p>Request\u306e\u691c\u8a3c\u306b\u5931\u6557\u3059\u308b\u3068\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u51e6\u7406\u304c\u6e21\u308b\u3053\u3068\u306a\u304f\u3001HTTP response 302\u304c\u30d6\u30e9\u30a6\u30b6\u30fc\u306b\u8fd4\u3055\u308c\u307e\u3059\u3002\u305d\u306e\u3068\u304d\u3001\u9001\u4fe1\u30d5\u30a9\u30fc\u30e0\u3092\u53d6\u5f97\u3057\u305fURL\u304c\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u5148\u306b\u6307\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3068\u304d$errors\u3068\u3044\u3046\u5909\u6570\u304c\u3064\u304f\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>old\u95a2\u6570\u3092\u4f7f\u3063\u3066\u30e6\u30fc\u30b6\u30fc\u304c\u9001\u4fe1\u3057\u305f\u5024\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\n@error \u3068\u3044\u3046blade\u306e\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3067\u30a8\u30e9\u30fc\u304c\u3042\u3063\u305f\u3068\u304d\u306e\u51e6\u7406\u3092\u5206\u5c90\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">resources\/views\/oligo\/create.blade.php<\/h5>\n    <pre class=\"code\">\n@extends(&#039;oligo.module&#039;)\n \n@section(&#039;feature&#039;)\n&lt;x-feature id=&#039;oligo-create&#039;&gt;\n  &lt;form action=&quot;{{ route(&#039;web.oligo.store&#039;) }}&quot; method=&quot;POST&quot;&gt;\n    @csrf\n    &lt;dl&gt;\n      @foreach([\n        &#039;name&#039; =&gt; &#039;\u540d\u524d&#039;,\n        &#039;sequence&#039; =&gt; &#039;\u914d\u5217&#039;,\n        &#039;updated_at&#039; =&gt; &#039;\u4f5c\u6210\u65e5&#039;,\n        &#039;owner&#039; =&gt; &#039;\u6240\u6709\u8005&#039;,\n      ] as $field =&gt; $label)\n        &lt;dt&gt;{{ __($label) }}&lt;\/dt&gt;\n        &lt;dd&gt;\n          &lt;input type=&#039;text&#039; name=&#039;{{ $field }}&#039;\n            value=&quot;{{ old($field) }}&quot;\n            style=&quot;@error($field) border: 2px solid red @enderror&quot;\n          &gt;\n          @error($field)\n            &lt;p style=&#039;color: red&#039;&gt;{{ $message }}&lt;\/p&gt;\n          @enderror\n        &lt;\/dd&gt;\n      @endforeach\n      &lt;dt&gt;&lt;button type=&#039;submit&#039;&gt;\u767b\u9332&lt;\/button&gt;&lt;\/dt&gt;\n    &lt;\/dl&gt;\n  &lt;\/form&gt;\n&lt;\/x-feature&gt;\n@endsection\n<\/pre>\n<\/div>\n<p>\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u304c\u7570\u306a\u308b\u3060\u3051\u306a\u306e\u3067\u3001foreach\u3092\u4f7f\u3063\u305f\u7e70\u308a\u8fd4\u3057\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30d5\u30a1\u30a4\u30eb\u306e\u5165\u51fa\u529b<\/h2>\n<h3>\u30d5\u30a1\u30a4\u30eb\u3078\u66f8\u304d\u51fa\u3057<\/h3>\n<p>\/oligo \u3078 POST \u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3057\u307e\u3059\u3002\u5f8c\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u5c0e\u5165\u3057\u3001\u305d\u308c\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5165\u51fa\u529b<\/p>\n<p>storage\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b\u306e\u304c\u6a19\u6e96\u3067\u3059\u3002\u5916\u90e8\u304b\u3089\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3055\u308c\u306a\u3044\u3082\u306e\u306fapp\/private\u3082\u3057\u304f\u306fapp\/public\u306b\u7f6e\u304d\u307e\u3059\u3002\u3053\u308c\u3089\u3078\u306e\u30d1\u30b9\u3092 storage_path()\u3067\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>OligoController\u306estore\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u3078\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">app\/Http\/Controllers\/OligoController.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nnamespace App\\Http\\Controllers;\n \nuse App\\Http\\Requests\\OligoRequest;\n \nclass OligoController\n{\n    public function index(){\n        return view(&#039;oligo.index&#039;);\n    }\n \n    public function create(){\n        return view(&#039;oligo.create&#039;);\n    }\n \n    public function store(OligoRequest $request){\n        $validated = $request-&gt;validated();\n        $data = [];\n        foreach([&#039;name&#039;, &#039;sequence&#039;, &#039;created_at&#039;, &#039;owner&#039;] as $key){\n            $data[] = sprintf(&#039;&quot;%s&quot;&#039;, $validated[$key] ?? &#039;&#039;);\n        }\n        $csv = storage_path(&#039;app\/private\/oligo.csv&#039;);\n        file_put_contents($csv, implode(&#039;,&#039;, $data).PHP_EOL, FILE_APPEND);\n \n        return redirect()-&gt;route(&#039;web.oligo.index&#039;)-&gt;with(&#039;status&#039;, &#039;\u4fdd\u5b58\u3057\u307e\u3057\u305f&#039;);;\n    }\n}\n<\/pre>\n<\/div>\n<h3>\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f<\/h3>\n<p>index\u30e1\u30bd\u30c3\u30c9\u3067csv\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">app\/Http\/Controllers\/OligoController.php<\/h5>\n    <pre class=\"code\">\n&lt;?php\n \nnamespace App\\Http\\Controllers;\n \nuse App\\Http\\Requests\\OligoRequest;\n \nclass OligoController\n{\n    public function index(){\n        $csv = storage_path(&#039;app\/private\/oligo.csv&#039;);\n        $fp = fopen($csv, &#039;r&#039;);\n        $items = [];\n        while($row = fgetcsv($fp)){\n            $items[] = array_combine([&#039;name&#039;, &#039;sequence&#039;, &#039;created_at&#039;, &#039;owner&#039;], $row);\n        }\n        fclose($fp);\n        return view(&#039;oligo.index&#039;, compact(&#039;items&#039;));\n    }\n \n    public function create(){\n        return view(&#039;oligo.create&#039;);\n    }\n \n    public function store(OligoRequest $request){\n        $validated = $request-&gt;validated();\n        $data = [];\n        foreach([&#039;name&#039;, &#039;sequence&#039;, &#039;created_at&#039;, &#039;owner&#039;] as $key){\n            $data[] = sprintf(&#039;&quot;%s&quot;&#039;, $validated[$key] ?? &#039;&#039;);\n        }\n        $csv = storage_path(&#039;app\/private\/oligo.csv&#039;);\n        file_put_contents($csv, implode(&#039;,&#039;, $data).PHP_EOL, FILE_APPEND);\n \n        return redirect()-&gt;route(&#039;web.oligo.index&#039;)-&gt;with(&#039;status&#039;, &#039;\u4fdd\u5b58\u3057\u307e\u3057\u305f&#039;);;\n    }\n}\n<\/pre>\n<\/div>\n<p>view\u306e\u307b\u3046\u3067\u914d\u5217\u3092\u8868\u306b\u7d44\u307f\u4e0a\u3052\u307e\u3059\u3002<\/p>\n<div class=\"code-block-wrapper\">\n            <h5 class=\"source-file\">resources\/views\/oligo\/index.blade.php<\/h5>\n    <pre class=\"code\">\n@extends(&#039;oligo.module&#039;)\n \n@section(&#039;feature&#039;)\n&lt;x-feature id=&#039;oligo-index&#039;&gt;\n  &lt;table&gt;\n    &lt;thead&gt;\n      &lt;tr&gt;&lt;th&gt;id&lt;\/th&gt;&lt;th&gt;\u540d\u524d&lt;\/th&gt;&lt;th&gt;\u914d\u5217&lt;\/th&gt;&lt;th&gt;\u4f5c\u6210\u65e5&lt;\/th&gt;&lt;th&gt;\u6240\u6709\u8005&lt;\/th&gt;&lt;\/tr&gt;\n    &lt;\/thead&gt;\n    &lt;tbody&gt;\n      @foreach($items as $item)\n        &lt;tr&gt;\n          &lt;td&gt;{{ $item[&#039;name&#039;] }}&lt;\/td&gt;\n          &lt;td&gt;{{ $item[&#039;sequence&#039;] }}&lt;\/td&gt;\n          &lt;td&gt;{{ $item[&#039;created_at&#039;] }}&lt;\/td&gt;\n          &lt;td&gt;{{ $item[&#039;owner&#039;] }}&lt;\/td&gt;\n        &lt;\/tr&gt;\n      @endforeach\n    &lt;\/tbody&gt;\n  &lt;\/table&gt;\n&lt;\/x-feature&gt;\n@endsection\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"Laravel\u3092\u4f7f\u3063\u3066\u7814\u7a76\u5ba4\u306e\u6750\u6599\u30fb\u30b5\u30f3\u30d7\u30eb\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u3092\u958b\u767a\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u4ee5\u4e0b\u306e\u524d\u56de\u306e\u7d42\u4e86\u6642\u70b9\u306e\u72b6\u614b\u3092\u518d\u73fe\u3067\u304d\u307e\u3059\u3002 $ git clone https:\/\/kiku3.tsbio.info\/git\/study-la [&hellip;]","protected":false},"author":1,"featured_media":0,"parent":2658,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2691","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/pages\/2691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/comments?post=2691"}],"version-history":[{"count":41,"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/pages\/2691\/revisions"}],"predecessor-version":[{"id":2951,"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/pages\/2691\/revisions\/2951"}],"up":[{"embeddable":true,"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/pages\/2658"}],"wp:attachment":[{"href":"https:\/\/biochemistry.isc.chubu.ac.jp\/labo\/suzuki\/wp-json\/wp\/v2\/media?parent=2691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}