Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

Date field displays current date when it is Null

In my Laravel-5.8 application, I have a field called hire_date. In the database, the datatype is date and default is NULL.

Model

protected $fillable = [
              'id',
              'employee_code',
              'hire_date',
            ];


 protected $dates = [
     'hire_date',
  ];	

public function setHireDateAttribute($value)
{
    $this->attributes['hire_date'] = Carbon::createFromFormat('d-m-Y', $value);
}
    
public function getHireDateAttribute($input)
{
         return Carbon::parse($input)->format('d-m-Y');
}   

View

<p for="">: {{ $employee->hire_date }} </p>

I want to display None when the date is Null.

But why is it showing today's date (Hire Date 30-07-2020) instead of null?

Thanks

0 likes
1 reply

Please or to participate in this conversation.