Hello @truongvietgroup
The error is that your $matches array doesn't have anything on index 1. (So your pattern didn't match)
You can prevent the error by checking if $matches[1]
exist.
protected function getDateFromLine($line)
{
preg_match('/^[([^\]]+)]/', $line, $matches);
if (isset($matches[1])) {
// we have an result
return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
}
// Return what you want if there isn't anything available.
return Carbon::now();
}
ps. I have update your post to get some code blocks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community