LoginSignup
21
18

More than 3 years have passed since last update.

Laravel form内 old関数使用例

Posted at

inputタグ
name属性の値を、old()の引数に入れる。

 <input type="title" name="title" value="{{ old('title') }}" class="form-control" id="input_title" placeholder="old関数の引数にname属性で指定した値を入れてる。">

textareaタグ
ここにold()入れる。 oldの引数にはname属性の値を入れる。

 <textarea type="text" name="body" class="form-control" id="input_body">{{ old('body') }}</textarea>

selectタグ
selectのname属性の値をold()の引数に指定
if分でidの値が「1」なら@if(old('id')=='1') selected @endif がselectedされる感じ。

<select name="id">
    <option value="1" selected @if(old('id')=='1') selected  @endif>1</option>
    <option value="2" @if(old('id')=='2') selected  @endif>2</option>
    <option value="3" @if(old('id')=='3') selected  @endif>3</option>
</select>
21
18
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
21
18