lundi 15 avril 2019

Leading 0 is being removed

I have a problem I've never come across before in the 14 months I've been using Laravel.

I have a user registration system. A pretty basic requirement for any application right. I have the usual credentials name, username, email, password, and a phone number.

If I submit the number in the following format 086123456. The leading 0 is being removed from what is saved in the DB. The phone_number field is a integer.

Any idea what is going on here.

User Model

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Property;
use Tymon\JWTAuth\Contracts\JWTSubject;


class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $fillable = [
        'first_name', 'last_name', 'username', 'email', 'phone_number', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function properties()
    {
        return $this->hasMany(Property::class);
    }

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }
}

Register Function

 public function register() 
    {
        $user =  User::create(['first_name' => request('first_name'), 'last_name' => request('last_name'), 'username' => request('username'), 'email' => request('email'), 'phone_number' => request('phone_number'), 'password' => bcrypt(request('password'))]);
        return response()->json($user);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire