Field return in Laravel

Asked

Viewed 289 times

0

I have the following field stored in my database:

inserir a descrição da imagem aqui

When trying to return it in view by Laravel 5.2 he is returning only the 45 the rest is not.

the field is defined this way in the bank:

inserir a descrição da imagem aqui

But other fields like phone are returning correctly.

Does anyone know what it could be?

  • would have an excerpt from your code to demonstrate how you are performing the request ?

1 answer

1


I recommend that you remove the score before storing these values, it will facilitate comparisons, searches and any other operation involving this column.

To solve your problem, you can use the attribute casting eloquent model. Within your model class, try to define the casts as a array, and within it his field as string, for example:

/**
 * The attributes that should be casted to native types.
 *
 * @var array
 */
protected $casts = [
    'cnpj' => 'string',
];

If you still don’t solve it, try modifying your Migration to use the method string, thus:

Schema::create('customers', function (Blueprint $table) {

    ....

    $table->string('cnpj', 14)->nullable();

    ....

}

For more information you can visit official documentation of Laravel on attribute casting.

  • 1

    Perfect.!! on my Migration I am using char and in the attribute casts put as char and it worked perfectly.. Vlws!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.