dongzu0742 2016-07-02 12:06
浏览 157
已采纳

Laravel:在数据库中保存空字符串,即使它在表单中不是空输入

When I type in my registration form in app name,email,and phone the phone is not displayed and the sting are saved in strange format.

When I run php artisan tinker:

 DB::table('user1s')->get();
=> [
     {#640
       +"id": 1,
       +"name": """
         \x09
         \x09sda\t
         """,
       +"email": """
         \x09
         \x09sds\t
         """,
       +"phone_number": "",
       +"created_at": "2016-07-02 11:28:04",
       +"updated_at": "2016-07-02 11:28:04",
     },
     {#642
       +"id": 2,
       +"name": """
         \x09
         \x09da
         """,
       +"email": """
         sd\x09
         \x09
         """,
       +"phone_number": "",
       +"created_at": "2016-07-02 11:33:56",
       +"updated_at": "2016-07-02 11:33:56",
     },
     {#643
       +"id": 3,
       +"name": """
         more in-\x0D
         \x09
         """,
       +"email": """
         \x09
         \x09more in-
         """,
       +"phone_number": "",
       +"created_at": "2016-07-02 11:52:43",
       +"updated_at": "2016-07-02 11:52:43",
     },
   ]

My form in the view looks like:

@extends('layout')


@section('content')
        <div class="row">
    <div class="col-md-6 col-md-offset-3">

        <h1>    Welcome please register!    </h1>

    <h1>All users</h1>

     @foreach ($user1s as $user1)
        <div>
            {{ $user1->phone_number }}
        </div>

    @endforeach 

        <hr>
        <h3>Fill in required informations</h3>

        <form  method="POST" action=" "> 
                <input name="_token" type="hidden" value="{{ csrf_token() }}"/>


            <ul class="list-group" >

                Name
                <div class="form-group" title="name" >
                    <textarea name="name" class="form-control" ></textarea>
                </div>


                Email
                <div class="form-group"  title="email"> 
                    <textarea name="email"  class="form-control" ></textarea>
                </div>

                Phone number    
                <div class="form-group"  title="phone_number"> 
                    <textarea name="phone_number"  class="form-control" ></textarea>
                </div>


                    <div class="form-group" >
                    <button class="btn btn-primary">Register</button>
                    </div>

            </ul>
        </form>
        @foreach($errors->all() as $error)
        {{ $error }}
        @endforeach
    </div>
</div>

@endsection

And my migration:

public function up()
{
    Schema::create('user1s', function (Blueprint $table) {
        $table->increments('id');
        $table->string("name");
        $table->string("email");
        $table->string("phone_number");
        $table->timestamps();
    });
}

Somebody sees the problem?

  • 写回答

1条回答 默认 最新

  • douxi3432 2016-07-02 12:36
    关注

    The problem here lies in your Controller (or end route) code. As said in the comments, you've missed out saving of the phone_number item.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划