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

Solutions on MaxInterview for laravel postgresql trying to access array offset on value of type int by the best coders in the world

showing results for - "laravel postgresql trying to access array offset on value of type int"
Gloria
17 Jul 2020
1# I found this issue only occured with POSTGRESQL Database
2# I was using sqlite and there was no issue but the production
3# server running postgresql had the issue because it treated
4# database columns of int type as int and not string as sqlite does
5# you can dd your data and you should see that it appears as string
6
7# To solve it I wrapped the value I was retrieving around the php
8# (string) helper to change it to string
9
10#suppose you want to get the second value of the data 8900
11# thus 9 in this case
12# this fails
13$name = User::first()->aniversary[1];
14
15# try this instead
16$name = ((string)User::first()->aniversary)[1];
17