表格
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('email')->nullable()->unique();
$table->string('password', 60);
$table->string('confirmation_code');
$table->boolean('confirmed')->default(config('access.users.confirm_email') ? false : true);
$table->string('street')->nullable();
$table->string('city')->nullable();
型号
protected $fillable = [
'email',
'street',
'city',]
Controller
$user = JWTAuth::parseToken()->authenticate();
$user->street = $request->street;
$user->city = $request->city;
$user->save();
当我在 postman 中使用 return response()->json($user);
运行我的函数时我明白了
{
"id": 5,
"name": null,
"email": "1@1.com",
"status": 0,
"confirmed": false,
"street": "Ulloa",
"city": null,}
当我 dd($request->all())
我明白了
array:2 [
"city" => "Woodside"
"street" => "Ulloa"
]
问题
为什么“城市”值在 MySQL 数据库中为空?
最佳答案
请求中有city_
键,但没有city
,这就是$request->city
为空的原因。
关于php - 保存来自 Laravel 的请求时 mysql 中缺少记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40959874/