dongwan0574 2017-06-29 10:55
浏览 59
已采纳

Laravel多个表单属性需要保存在数据库中

I'm using this view. What I need is fill the database with complete name.

enter image description here 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 ?

  • 写回答

1条回答 默认 最新

  • dqdjfb2325 2017-06-29 10:59
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效