Laravel多个表单属性需要保存在数据库中
问题描述:
I'm using this view. What I need is fill the database with complete name.
This is the view code segment.
<label>Name with Initials</label>
<div class="input-group">
<span class="input-group-addon">
<select id="name_with_initials" name="name">
<option selected="selected" value="mr">Mr.</option>
<option value="mrs">Mrs.</option>
<option value="miss">Miss.</option>
</select>
</span>
<input type="text" name="name_with_initials" class="form-control" placeholder="Name with Initials">
</div>
Here is the store function in controller.
$registerdetails = new registerdetails;
$title = Input::get('name');
$name = Input::get('name_with_initials');
$name_with_initials = $title.' '.$name;
$registerdetails ->name_with_initials = $request ->name_with_initials;
My model attribute for that is name_with_initials
This works fine,but save only the name not as mr mrs why is that ?
答
you have error in this line, here you are storing the complete name in $name_with_initials
variable but at the time of storing still you are storing the data which came through request. change this line
$registerdetails ->name_with_initials = $request ->name_with_initials;
with
$registerdetails ->name_with_initials = $name_with_initials;