php - 保存来自 Laravel 的请求时 mysql 中缺少记录

标签 php mysql laravel

表格

 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/

相关文章:

javascript - 使用 PHP/Javascript 创建图像,在图像周围提供灰色输出

mysql - Innodb和Myisam在Mysql中的性能差异

mysql - MySQL 中何时使用单引号、双引号和反引号

rest - 在 codeception 中将文件发送到 Restful 服务

mysql - Laravel Datatables ajax无法发送参数进行查询

php - Logo在移动版二十十三主题wordpress上被截断

PHP 在 require 时避免 sleep

php - 重新格式化 Excel 布局以适应 JSON

php - MySQL 使用过滤器、COUNT、GROUP BY/LIMIT/ORDER BY 和子查询查询 HTML 表

laravel - 无法声明类 Controller,因为该名称已在使用中