Field return on laravel

0

I have the following field saved in my database:

WhentryingtoreturnitintheviewbyLaravel5.2itisonlyreturning45therestisnot.

Thefieldisdefinedlikethisinthedatabase:

But other fields like phone are returning correctly.

Does anyone know what it could be?

    
asked by anonymous 19.06.2016 / 22:41

1 answer

1

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

To solve your problem, you can use attribute casting of eloquent model. Within your template class, try setting the casts property to array , and within it your string field, for example:

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

If it still does not resolve, try modifying your migration to use the string method, like this:

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

    ....

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

    ....

}

For more information, you can visit Laravel's official documentation on attribute casting .

    
20.06.2016 / 18:09