fer*_*3ed -2 php laravel laravel-5 php-7
我有一个问题,在我使用Laravel的14个月中从未遇到过。
我有一个用户注册系统。任何应用程序权利的基本要求。我有通常的凭据名称,用户名,电子邮件,密码和电话号码。
如果我以以下格式提交号码086123456。则从数据库中保存的内容中删除了前导0。phone_number字段是整数。
不知道这是怎么回事。
用户模型
<?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 [];
}
}
Run Code Online (Sandbox Code Playgroud)
注册功能
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);
}
Run Code Online (Sandbox Code Playgroud)
phone_number字段是整数。
这就是问题。086123456不是有效的整数,因此将剥离0,而仅保留86123456。您可能会想用一个string值来表示这一点,因为大规模的整数值,或无效的整数值,电话号码常见的,像字符+,-,(和)。
| 归档时间: |
|
| 查看次数: |
50 次 |
| 最近记录: |