Skip to content
Advertisement

Time format in laravel migration?

I want to have an input, where you put a time in EU format like 12:00 or 21:34. (hh:mm) How do I do that?

JavaScript

This is what I have, but it’s obviously wrong.

Advertisement

Answer

In laravel 5.6 you have this new feature that you can cast your timestamp so your migration should be like this

JavaScript

And in your Post model you can simply do this:

JavaScript

Edit
If you are NOT using laravel 5.6 you can use Accessors & Mutators to easily manipulate data on setting on database or getting it from database so you can do something like this

JavaScript

And every time that you echoing it out in your blade or wherever like this {{ $post->begin }} it automatically changes the format for you.

Hope that helps.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement