noblemfd
1 month ago
176
3
Laravel

How to display Unknown on the view blade for date_of_birth

Posted 1 month ago by noblemfd

In my Laravel-5.8, I have this code:

protected $fillable = [
              'id',
              'first_name',
               'last_name',
              'date_of_birth',

          ];

protected $dates = [
      'date_of_birth',
  ];

public function setDateOfBirthAttribute($value)
{
    $this->attributes['date_of_birth'] = Carbon::createFromFormat('d-m-Y', $value);
}

public function getDateOfBirthAttribute($input)
{
   return Carbon::parse($input)->format(config('app.date_format'));   
}

config/app.php

    'date_format' => 'd/m/Y',
    'date_format_js' => 'dd/mm/yy', 

view

 <div class="col-md-4">
    <p for="">: {{ $employee->date_of_birth }} </p>
 </div

Whenever the date_of_birth field is null in the database, the application displays today's date on the view blade for the date of birth:

04/08/2020

How do I display "Unknown" on the view blade for date_of_birth whenever the date_of_birth is null?

Thanks

Please sign in or create an account to participate in this conversation.