php - postgresql 中的最后三列值在通过 php laravel 发送时变为 null

标签 php postgresql laravel

if ($dataRaw['type'] == "CheckIn") {
$res = $this->fetchLocations($dataRaw['entityid'], 'checkins');
\App\CheckIn::create([
    'type'                   => $dataRaw['type'],
    'reason'                 => $dataRaw['checkinreason'],
    'device_id'              => $ssid,
    'deviceuniqueidentifier' => $dataRaw['deviceuniqueidentifier'],
    'date_time'              => gmdate("Y-m-d H:i:s", hexdec(substr($dataRaw['entityid'], 0, 8))),
    'entityid'               => $dataRaw['entityid'],
    'latitude'               => $res['Latitude'],
    'longitude'              => $res['Longitude'],
    'address'                => $res['Address'],
    'queue'                  => $k,
]);
}

if ($dataRaw['type'] == "Event") {
$res = $this->fetchLocations($dataRaw['entityid'], 'events');
\App\Events::create([
    'type'                   => $dataRaw['type'],
    'reason'                 => $dataRaw['eventtype'],
    'device_id'              => $ssid,
    'deviceuniqueidentifier' => $dataRaw['deviceuniqueidentifier'],
    'date_time'              => gmdate("Y-m-d H:i:s", hexdec(substr($dataRaw['entityid'], 0, 8))),
    'entityid'               => $dataRaw['entityid'],
    'queue'                  => $k,
    'latitude'               => $res['Latitude'],
    'longitude'              => $res['Longitude'],
    'address'                => $res['Address'],
]);
}

这是我进行查询的地方,它为最后三列纬度经度和地址发送空值。我还检查了 $res 数组中出现的值,它们也打印得很好。发布的日志中也没有错误。

事件.php

  <?php
  namespace App;
  use Illuminate\Database\Eloquent\Model;
  class Events extends Model
 {
     protected $table = 'events';
     protected $fillable = ['type', 'reason', 'is_processed', 
    'device_id', 
    'deviceuniqueidentifier', 'date_time', 'entityid', 'queue', 
    'is_deleted'];
  }

最佳答案

将这些列添加到可填充数组中,如下所示:

protected $fillable = [
'type',
'reason',
'is_processed',
'device_id',
'deviceuniqueidentifier',
'date_time',
'entityid',
'queue',
'is_deleted',

// follwing lines missing
'latitude',
'longitude',
'address',
];

提示:您可以使用$cast让列值重新运行为 true 或 false:

protected $casts = [
  'is_processed' => 'boolean',
  'is_deleted' => 'boolean'
];

关于php - postgresql 中的最后三列值在通过 php laravel 发送时变为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44037184/

相关文章:

php - 是否有一个 PHP 函数可以计算一个值在数组中出现的次数?

php - 公司 table 上的 Laravel 5 和 Cashier

php - 如何从 jquery datepicker 列出一个月中的所有日期?

postgresql - 删除重复记录(有效)

node.js - ES6 异步/等待、ExpressJS 和 Postgres 事务

java - 使用 Java 连接到 MySQL 而无需使用 GPL

php - Laravel - 意外的 ':' 期待 '('

php - 附加 php 数组以获取所需的行输出

php - Laravel 中的 try-catch 样板

git gitlab laravel 不是所有的文件都添加了