Problems with charset in laravel

1

I have a Firebird database that was not built through migrations in Laravel , and it has ISO-8859-1 and I need to return an object in JSON format for my application, however, doing this, the following error occurs:

  

"The Response content must be the string of object implementing

asked by anonymous 07.10.2016 / 16:12

2 answers

0

You can use the Accessors & Mutators from , where formatting of the field is made direct model :

I'll propose an example , because in your question it does not have a model and it would be important to have and table layout by cause of the fields, but, I will generalize with a basic example.

Example:

In your specific case the display factor is what you need:

<?php

namespace App;    
use Illuminate\Database\Eloquent\Model;

class Noticias extends Model
{    
    public function getTituloAttribute($value)
    {
        return strtoupper($value);
    }
}

In the noticias table, there is a field titled title . a % mutation method that automatically does the specific conversion of the title field.

Standards:

  

get + field name + get

If the field is separated by Attribute($value) as an example underscore would be:

public function getPrimeiroNomeAttribute($value)

that is, initials in upper case between primeiro_nome

It also has underscore that would be a modification of change of sent value, also putting significant effects and changes on the value of this field, reflecting all this change in your table.

Standards:

  

set + field name + set

Code with the same field Attribute($value) of table titulo ( dummy example ):

public function setTituloAttribute($value)
{
     $this->attributes['titulo'] = $value;
}

Complete code dummy example noticias :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Noticias extends Model
{    
    // GET
    public function getTituloAttribute($value)
    {
        return strtoupper($value);
    }
    // SET
    public function setTituloAttribute($value)
    {
        $this->attributes['titulo'] = $value;
    }
}
    
08.10.2016 / 15:50
0

In my case I solved in Laravel's database config, defining collation = iso and charset = utf8

    'oracle' => [
        'driver' => 'oracle',            
        'host' => 'seu host',
        'port' => 'porta',
        'database' => 'database',
        'username' => 'user',
        'password' => 'senha',
        'charset' => 'utf8',
        'collation' => 'WE8ISO8859P1',
        'prefix' => '',
    ],
    
11.10.2016 / 17:13