Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String with a "b" prefix on records with accent

When I dump the property of my model and it has an accent it returns with this "b" prefix

dump($venda_item->produto->nomeproduto); // b"teste téste"

My database is setted to utf8 and utf8_general_ci collation

This causes me the following error Malformed UTF-8 characters, possibly incorrectly encoded when I'm returning the response in json, at this line

$json_response = Response::json($response, $this->getStatusCode(), $headers);

Update

I discovered that if I die and dump the record on the web route it shows normal teste téste

Route::get('/', function () {
    dd(App\Vendasitem::where('codigovi', 112685)->first()->produto->nomeproduto);
}

otherwise if I do the same in the controller or request and other files that I tryied it keeps returning me with the "b" prefix

Update 2

If I save my record like this PROMO - VIRICAPS (GUARANá + POLIVIT) 60 CáPS - CAIXA 18 UND and dump($venda_item->produto->nomeproduto); it returns me the right result with the accents.

All my database, including the column is set up to utf8mb4 and utf8mb4_unicode_ci

like image 758
SpaceDogCS Avatar asked Feb 13 '19 17:02

SpaceDogCS


1 Answers

If you already confirmed the encoding on your database. Have a look on config/database.php, on charset and collation proprieties.

'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci'

If the issue is on the "print" then you might use the utf8_encode function.

{{utf8_encode($yourVar)}}
like image 128
Tiago Mateus Avatar answered Oct 10 '22 22:10

Tiago Mateus