I have my web application running on server. I tested the code in local and it works fine. I’m getting id as int from local server but string in hosted server.
Using PHP 7.3
$data = DB::table('users') ->select('id') ->get(); $data = $data->pluck(id);
output => [1,2,3]
output => [“1″,”2″,”3”]
Can any one help to resolve this issue? I can do loop to type cast but there are 100’s for function in my controller. It is not possible to type cast each query.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
You can use casting Attribute Casting in your model
protected $casts = [ 'field_name1' => 'integer', ];
This is due to a missing plugin on the production server (hosting server).
You need to install the
mysqlnd plugin to fix the issue.
You have not mentioned which OS you are using. If it’s Linux, you can check whether
mysqlnd is installed like so
$ sudo dpkg -l | grep 'mysqlnd'
If it’s not installed, you need to install it like so (assuming you have php5)
$ sudo apt-get install php-mysqlnd
Package name might differ based on the PHP version.
Refer my answer for more information.