LoginSignup
0
0

More than 1 year has passed since last update.

Laravel jetstream プルダウンとチェックボックス

Last updated at Posted at 2022-01-10

Laravelでconfigフォルダにファイルを保存してから値を記述する方法について
2箇所に記述しております。

パターンA
従来の記述

①config直下に保存するファイル

app/config/prefecture.php
<?php 
return array(
  '0' => '未選択',
  '1' => '北海道', 
  '2' => '青森県', 
  '3' => '岩手県', 
  '4' => '宮城県',
  '5' => '秋田県', 
  '6' => '山形県', 
  '7' => '福島県', 
  '8' => '茨城県',
  '9' => '栃木県', 
  '10' => '群馬県', 
  '11' => '埼玉県', 
  '12' => '千葉県',
  '13' => '東京都', 
  '14' => '神奈川県', 
  '15' => '新潟県', 
  '16' => '富山県',
  '17' => '石川県', 
  '18' => '福井県', 
  '19' => '山梨県', 
  '20' => '長野県', 
  '21' => '岐阜県', 
  '22' => '静岡県', 
  '23' => '愛知県', 
  '24' => '三重県',
  '25' => '滋賀県', 
  '26' => '京都府', 
  '27' => '大阪府', 
  '28' => '兵庫県',
  '29' => '奈良県', 
  '30' => '和歌山県', 
  '31' => '鳥取県', 
  '32' => '島根県',
  '33' => '岡山県', 
  '34' => '広島県', 
  '35' => '山口県', 
  '36' => '徳島県',
  '37' => '香川県',
  '38' => '愛媛県',
  '39' => '高知県', 
  '40' => '福岡県',
  '41' => '佐賀県', 
  '42' => '長崎県', 
  '43' => '熊本県', 
  '44' => '大分県',
  '45' => '宮崎県', 
  '46' => '鹿児島県', 
  '47' => '沖縄県'
);
?>

続いてview

resources/views/posts/create.blade.php

<div class="form-group">
<tr><th>出身地</th><td>
<select type="text" class="form-control" name="prefecture">                 
@foreach(config('prefecture') as $key => $score)
<option value="{{ $score }}">{{ $score }}</option>
@endforeach
</select>
</div>

パターンB
チェックボックスの時
下記はチェックボックスでviewに記述する場合の記述。

下記のように一つしか選択できないformを実装する際は、radioで実装して下さい。

resources/views/posts/create.blade.php
   <div class="form-group row">
        <label>
         性別
         <p class="col-sm-4 col-form-label"></p>
               <div class="col-sm-8">
               <label>{{ Form::radio('gender', "未選択") }}未選択</label>
               <label>{{ Form::radio('gender', "男性") }}男性</label>
               <label>{{ Form::radio('gender', "女性") }}女性</label>
              </div>
          </div>
      </label>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0