Skip to content
Advertisement

how to make Carbon null in laravel?

I’m making a table in Laravel and I want my “besttime” to be a nullable but it’s returning the current time if I keep it empty. (I’m using carbon because I want the H:i format without the seconds) here’s what my input looks like

JavaScript

Advertisement

Answer

I will suggest you to add mutators in model so you can keep code simpler in blade file

JavaScript

so in your view you can do

JavaScript

suppose if you dont want to modify orginal values then you can create custom attribute and append it to request

JavaScript

and set

JavaScript

so in your view you can do

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