Jasper Helmich
Jasper Helmich

Reputation: 751

Laravel not storing phone number

I am working on a school project, and I have a registration form.

I am working in laravel 5 and am using the auth package of laravel.

I added my extra registration forms like this

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
        'lastName' => 'required|string|max:55|',
        'streetAdress' => 'required|string|max:255|',
        'houseNumber' => 'required|integer|min:1|',
        'city' => 'required|string|max:255|',
        'postal_code' => 'required|string|max:255|',
        'user_phone_number' => 'required|numeric|min:10|',
        'birth_day' => 'required|date|min:1|',
        'user_parent_name' => 'required|string|max:255|',
        'user_parent_email' => 'required|email|max:255|',
        'user_parent_phone' => 'required|numeric|min:10|',
    ]);
}

That is my validator here is my create

protected function create(array $data)
{
    $birthday = explode('-', $data['birth_day']);
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'lastName' => $data['lastName'],
        'streetAdress' => $data['streetAdress'],
        'houseNumber' => $data['houseNumber'],
        'city' => $data['city'],
        'user_phone_number' => $data['user_phone_number'],
        'postal_code' => $data['postal_code'],
        'birth_day_day' => $birthday[2],
        'birth_day_month' => $birthday[1],
        'birth_day_year' => $birthday[0],
        'user_parent_name' => $data['user_parent_name'],
        'user_parent_email' => $data['user_parent_email'],
        'user_parent_phone' => $data['user_parent_phone'],
    ]);
}

Here is my html

<input id="user_phone_number" type="number" class="form-control" name="user_phone_number" value="{{ old('user_phone_number') }}" required>

In my database I have a column called user_phone_number. Everything else does store but the user_phone_number is still NULL

Thanks in advance

Upvotes: 1

Views: 3514

Answers (2)

ND verma
ND verma

Reputation: 297

**if you are store phone no in database use this migration work for me

$table->bigInteger('phone');

Upvotes: 0

Jasper Helmich
Jasper Helmich

Reputation: 751

I was looking through my model and i found the problem. i didnt had the fillable option for user_phone_number,

protected $fillable = [
    'name', 'email', 'password', 'lastName', 'streetAdress', 'houseNumber', 'city', 
    'postal_code', 'birth_day_year', 'user_phone_number',  'birth_day_month', 'birth_day_day', 'user_parent_name', 
    'user_parent_email', 'user_parent_phone',
];

Was missing user_phone_number

Upvotes: 2

Related Questions