ブール型の1つのカラムがあり、nullの場合「未」、1の場合「済」としラジオボタンで表示する。
表示イメージ

モデル
public function inputActivate(){
$true='';$false='';
($this->カラム名) ? $true = 'checked' : $false = 'checked';
$html = <<<EOF
<input type="radio" id="false" name="カラム名" value="" {$false} />
<label for="false">未</label>
<input type="radio" id="true" name="カラム名" value="1" {$true} />
<label for="true">済</label>
EOF;
return $html;
}
コントローラ
public function メソッド名(Request $request){
$example = モデルのクラス名::find($request->id);
return view('ビューテンプレート名',['form' => $example]);
}※リクエストクエリの「id」を元にレコードを取得し、ビューテンプレートに渡している(リクエストクエリのidは必ず入っている前提)
ビューテンプレート
{!!$form->inputActivate()!!}ラジオボタンのvalueにnullか1のどちらかが入るので、レコードの更新時もちゃんと反映される。



コメントを残す