Laravel 5 + SQL Server和编码错误

I'm using Laravel 5 and SQL Server to fetch some data.

Whenever the data has some special characters (éêè etc.) Laravel doesn't show the column value, as if it was just nothing. (not null either).

I tried some SQL commands via tinker, and got the same results. My titles doesn't show up whenever they have special characters.

The database is encoded with this collation : Latin1_General_CP1_CI_AS And my database.php looks like this :

<?php
      return [
      'connections' => [
                'mysql' => [/*my mysql connection*/],
                'dbmssql' => [
                            'driver'    => 'sqlsrv',
                            'host'      => 'host',
                            'database'  => '',
                            'username'  => 'username',
                            'password'  => 'password',
                            'prefix'    => '',
                            'collation' =>  'SQL_Latin1_General_CP1_CI_AS',
                            'charset'   =>  'latin1'
                        ],
                ]
      ];

We have tried almost everything. Changing the collation/charset, adding a "Cast()" to our SQL commands etc. None of them works. We can't even get the data with bad encodings. It just returns nothing.

Here is the tinker result :

  • The first result has been added through Laravel, so the encoding works Laravel-side, but on the SQL Server its badly encoded
  • Second result has no special char. and show up normally on both side
  • Third result has special char. on SQL Server, Laravel doesn't show it at all.
      id: "1",
      titre: "ûéÉàÀêÊïÏçÇ",
      etat: "1",
      created_at: "May 29 2015 08:04:43:000PM",
      updated_at: "Jun  1 2015 03:24:44:000PM"
  },
  <stdClass #000000005a3cad49000000000aae376c> {
      id: "2",
      titre: "Administration",
      etat: "1",
      created_at: "Jun  1 2015 08:55:00:000AM",
      updated_at: "Jun  1 2015 08:55:00:000AM"
  },
  <stdClass #000000005a3cad4c000000000aae376c> {
      id: "3",
      titre: ,
      etat: "1",
      created_at: "Jun  1 2015 08:55:00:000AM",
      updated_at: "Jun  1 2015 08:55:00:000AM"
  },

Has anyone run into something similar?

UPDATE

I finally made it work using the mutators! Here is my Model function code if anyone else runs into this situation.

public function getTitreAttribute($title){
    return utf8_encode($title);
}

public function setTitreAttribute($titre){
    $this->attributes['titre'] =  utf8_decode($titre);
}