untymage's avatar

Which data type supports Integer that start with 0

In migration which method should i set to support numbers that start with 0 ? for example 000012329

0 likes
5 replies
Sinnbeck's avatar

Either use a string column or use integer and add the leading zeroes after getting them from the database

1 like
Snapey's avatar

use regular integer, then create an accessor in eloquent model

public function getSupportNoAttribute()
{
    return sprintf("%09d", $this->supportNo);
}

replace supportNo with your column name

If the column is also a primary key, you should give this accessor a different name

untymage's avatar

@snapey When i using regular integer column i dont know why php converts my number to another number for example 00001231231 will be 340633

Snapey's avatar

when you do what with it? Its not going to just change itself. Show some code?

untymage's avatar

in posts migration:

$table->integer('number');

creating post by relation ship:

$user->posts()->create(['number' =>00001231231]);

But php converts that number to 340633 in database

Please or to participate in this conversation.