Carbon (laravel) deal with invalid date

前端 未结 4 1949
面向向阳花
面向向阳花 2021-02-20 05:22

I have a quite simple problem.. I use the Carbon::parse($date) function with $date = \'15.15.2015\'. Of course it can not return a valid string because

4条回答
  •  遥遥无期
    2021-02-20 05:57

    You can catch the exception raised by Carbon like this:

    try {
        Carbon::parse($date);
    } catch (\Exception $e) {
        echo 'invalid date, enduser understands the error message';
    }
    

提交回复
热议问题