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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助