Answers for "laravel postgresql Trying to access array offset on value of type int"

PHP
0

laravel postgresql Trying to access array offset on value of type int

# I found this issue only occured with POSTGRESQL Database
# I was using sqlite and there was no issue but the production
# server running postgresql had the issue because it treated
# database columns of int type as int and not string as sqlite does
# you can dd your data and you should see that it appears as string

# To solve it I wrapped the value I was retrieving around the php
# (string) helper to change it to string

#suppose you want to get the second value of the data 8900
# thus 9 in this case
# this fails
$name = User::first()->aniversary[1];

# try this instead
$name = ((string)User::first()->aniversary)[1];
Posted by: Guest on August-29-2021

Code answers related to "laravel postgresql Trying to access array offset on value of type int"

Browse Popular Code Answers by Language