How to put the zerofill constraint in Laravel 5.6?

2

Good afternoon. I'm having a problem to make use of the zerofill constraint in Laravel because vi that is not in the documentation.

I have a field in my table which is a license plate and in my view I am limiting this field to 5 digits, so the maximum value it can reach is: 99999. But I would like it when the user types an unused license number all digits, spaces were filled with 0.

For example, the user reports the registration number: 450. The bank should be showing 00450.

How can I do this in Laravel?

My migration looks like this:

$table->integer('matricula')->unique();
    
asked by anonymous 12.10.2018 / 22:31

1 answer

0

You can use Mutators or Accessors to do this. Mutatosr would act as a SET , before saving in the database, it would check the number of digits and add the zeros at startup. Accessors would be like GET , when it takes the value from the database, it checks the number of digits and adds in front of the value, p>

You can see examples in the link:

link

    
15.10.2018 / 18:18