Laravel 5 charset does not work correctly on views. But it works well when I reset it from the controller

I ran into a charset problem. I am developing an application that uses a SQL Server database. The database was not created for this application, it exists and works very well. I can’t change anything in the database because it is too large and is used by many other applications.
I finished auth of my laravel 5 application, so I will create a view and show the name of the registered user in this view. Title: ADMINISTRADOR DA ACENTUAÇÃO. It uses some special characters.
In my opinion:

{!!Auth::user()->name!!} 

He shows:

ADMINISTRADOR DA ACENTUA O

But in my controller, before I get back, I did:

 die(\Auth::user()->name); 

and he shows me:

ADMINISTRADOR DA ACENTUAÇÃO

I am trying to do this in my view file:

  {!!Auth::user()->name!!} <?php die(); 

And it works great. This shows me:

ADMINISTRADOR DA ACENTUAÇÃO

This makes me believe that the occours error for something laravel makes after looking at it.

I do not know why this works well when I die on behalf of the user on the controller, but does not work when I echo his name on the view.

Can anybody help me?

PS:

  • My view file uses utf8 charset
  • I tried to echo using html tags and metaphorical characters without them. The problem occurs in both cases.
  • I tried to delete my view file and create a new one using utf8 charset. This does not work.
  • I tried using t23 tags instead of tags. This does not work.
+8
php utf-8 character-encoding laravel laravel-5
source share
4 answers

I solved this problem using this iver . I just went into my AppServiceProvider and applied the loading method:

 Blade::setEchoFormat('e(utf8_encode(%s))'); 

I do not know if this is being done correctly, but it works for me.

+3
source share

In general, adhering to UTF-8, life remains simple.

Be super thorough copying and pasting from anywhere to your code - basically always use Notepad ++ and use its conversion to UTF-8 (without specification) before copying and pasting into your code.

The first question is, how do the data get into your database?

Mega Top Tip If you are using a form, make sure that you set the attribute of the accepted character in the form element:

 <form accept-charset="UTF-8" 

Then make sure that all of your views (including error pages) have

 <meta charset="UTF-8"> 

Or if you are making HTML4

 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
+1
source share

Since successful and error response do not behave sequentially, the difference may be in the HTTP headers. If so, then it happens that Sqlserver and your browser use the same encoding, probably some default Windows, such as cp1252, while Laravel is configured to respond with a different encoding than the one used in the database .

Check the type of the contents of the HTTP header both when the view is called and when it dies () - if this is your problem, configure Laravel to send some header that is consistent with your templates and your database encoding (or, of course, recodes explicitly if necessary )

0
source share

I accidentally opened my UTF-8 encoded file in another text editor and saved. However, it automatically saved my UTF-8 file as ANSII . So I had to open the file again and save the file as UTF-8 encoded.

0
source share

All Articles