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
.