0

I am trying to fetch the records in laravel then it will give me following error.

Malformed UTF-8 characters, possibly incorrectly encoded

This is my code

$Login = DB::table('usermaster')

        ->where('Email', $uname)

        ->where('Password', md5($password))

        ->get();

    return response()->json($Login);
Andrew
  • 26,629
  • 5
  • 63
  • 86
Jay Chauhan
  • 296
  • 3
  • 11
  • Have you taken a look at https://stackoverflow.com/questions/31115982/malformed-utf-8-characters-possibly-incorrectly-encoded-in-laravel – KaffineAddict Mar 22 '18 at 14:10

1 Answers1

1

In my laravel query i am use a following code so it will give a this type of error...

Malformed UTF-8 characters, possibly incorrectly encoded

$BvoData = DB::table('test1')->select('test1.*')
        ->where("test1.Id", "".$id."")
        ->first();

$BvoData->temp1 = DB::table('temp1')->where('tmpdata', $BvoData->tmpdata)->get(); 

$BvoData->temp2 = DB::table('temp2')->where('Id', $id)->get();

return response()->json($BvoData);

but i will solve this error by doing following code...

$BvoData = DB::table('test1')->select('test1.*')
        ->where("test1.Id", "".$id."")
        ->first();

$BvoData = (array)  $BvoData;

$BvoData->temp1 = DB::table('temp1')->where('tmpdata', $BvoData->tmpdata)->get(); 

$BvoData["temp1"] = json_decode(json_encode($BvoData["temp1"]), True);


$BvoData->temp2 = DB::table('temp2')->where('Id', $id)->get();

$BvoData["temp2"] = json_decode(json_encode($BvoData["temp2"]), True);

return response()->json($BvoData);

by using json_decode and json_encode i solve my problem...

Jay Chauhan
  • 296
  • 3
  • 11
  • This solution did not work for me, still getting ""message": "Malformed UTF-8 characters, possibly incorrectly encoded"," error. Thanks. – Kamlesh Sep 06 '20 at 09:02