moonlight moonlight - 5 months ago 16
SQL Question

Laravel : Saving empty string in database even if it's not empty input in form

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?

Answer

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.