Support the ongoing development of Laravel.io →
Laravel
Last updated by @tvbeek 2 years ago.
0
moderator

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.