お世話になってます。
下記のコードにおいて、文字列を動的に扱う方法は
ありますでしょうか?ご教示下さい。
・現在
list.blade.php
<select name="pref" class="form-control select select-primary mbl" data-toggle="select"> <option value="">{{$mess}}</option> <optgroup label={{$mess2}> <option value="{{$pref}}" @if($pref=={{$pref}}) selected @endif>{{$pref}}</option> <option value="{{$pref2}}" @if($pref=={{$pref2}}) selected @endif>{{$pref2}}</option> </optgroup>
↑上記ではエラー構文エラー(syntax error, unexpected '<' )が出ます。
web.php
(一部省略) $str=mb_convert_encoding("全国","utf-8","sjis"); $str2=mb_convert_encoding("四国","utf-8","sjis"); $my_st=mb_convert_encoding("愛媛県","utf-8","sjis"); $my_st2=mb_convert_encoding("香川県","utf-8","sjis"); $hash=array( 'mess'=>$str, 'mess2'=>$str2, 'pref'=>$my_st, 'pref2'=>$my_st2, ); return view('pref.list')->with($hash);
・修正したい箇所
<option value="{{$pref}}" @if($pref==[ここ??をどのように]) selected @endif>{{$pref}}</option> <option value="{{$pref2}}" @if($pref==[ここ??をどのように]) selected @endif>{{$pref2}}</option>
以上、宜しくお願いします。
前提や要件 設定部分(設計部分)がこれだけでは見えません。まず思ったように組んでみた結果を教えてください。bladeでも裏で動いているのは結局PHPです。PHPできちんと組むことができればあとは同じはずです。

回答1件
あなたの回答
tips
プレビュー