I have a site, that uses laravel 4.2 (stable) with Eloquent. I am also using this User messaging system. I wanted to switch database from mysql to postgres. On mysql, everything worked fine. I changed configs to postgres, run all migrations and everything seemed to work, except parts, that use the messaging library, which gave this error:
Undefined property: stdClass::$numOfUnread
The first bit of info, I request from that library is number of unread messages for logged in user. After seeding, there are no messages.
I read about this error and there were couple of reasons, usually error in dev version of Laravel. In my case everything apart from that library works fine and this library also worked fine on mysql.
My config is:
'fetch' => PDO::FETCH_CLASS,
'default' => 'pgsql',
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => '****',
'username' => '****',
'password' => '****',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
I also tried to narrow the error in the library and I've found it in this file
public function getNumOfUnreadMsgs($user_id) {
$results = $this->db->select(
'
SELECT COUNT(mst.id) as "numOfUnread"
FROM '.$this->tablePrefix.'messages_status mst
WHERE mst.user_id=?
AND mst.status=?
',
[$user_id, self::UNREAD]
);
return (isset($results[0]))? $results[0]->numOfUnread : 0;
}
It looks like mysql returns:
array(1) { [0]=> object(stdClass)#881 (1) { ["numOfUnread"]=> int(1) } }
and postgres returns:
array(1) { [0]=> object(stdClass)#881 (1) { ["numofunread"]=> int(1) } }
Can I somehow force postgres to return field names with capital letters?