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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?