I always check here for what browsers support what.
https://caniuse.com/#search=input%20type%20date
<input type="date" placeholder="yyy-mm-dd">
Adding a placeholder can help you a bit and inform the user about the correct format.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using <input type="date"> on the front-end of my app without poly-filling date inputs. This leaves Safari ignoring the type="date" bit and just giving me a regular text input. The problem here is that a user can then type in a date like "October 5, 2020" and it passes the date validation on my front-end component and in my form request but Carbon looks to choke on the value with an "Unexpected data found. The separation symbol could not be found Data missing" error from Carbon.
I've currently solved the issue by making an explicit set mutator on the model of my date field however I'm wondering if there's a more "Laravel"-esque way of doing this? I've also found that because I'm using faker in my tests to generate a custom_date I have to write a case to flip between Carbon's instance and parse methods to avoid throwing errors and it all just feels a little bloated.
class FormRequest
{
public function rules() {
return [ 'custom_date' => 'nullable|date|after:today'];
}
}
class Model
{
protected $dates = ['custom_date'];
public function setCustomDateAttribute($date)
{
if ($date instanceof \DateTime) {
return $this->attributes['custom_date'] = Carbon::instance($date)
->format('Y-m-d H:i:s');
}
return $this->attributes['custom_date'] = $date != null
? Carbon::parse($date)->format('Y-m-d H:i:s')
: null;
}
}
class Controller
{
public function store(FormRequest $request)
{
Model::create($request->validated());
}
}
I think you are stuck doing it in Carbon like you are doing. There might be some method in Carbon that can make it easier for you but I couldn't find any at first glance.
You could maybe do some reqular expressions to check the format
Something like
^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$
Should cover most 'yyyy-mm-dd' and yyy/mm/dd
^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$.
Should cover dd-mm-yyy and dd/mm/yyyy
Please or to participate in this conversation.