Support the ongoing development of Laravel.io →
Laravel

Laravel Version: 9.24.0 PHP Version: 8.1.6 Database Driver & Version: N/A

After executing the command:: php artisan serve and access the link: http://127.0.0.1:8000/ I try to access the document file in the public folder and get an error message

2022-08-11 14:44:48 /assets/img/icons/spot-illustrations/bg-shape.png ................................................................................................................................................................................................ ~ 0s
2022-08-11 14:44:48 /assets/img/icons/spot-illustrations/shape-1.png ................................................................................................................................................................................................. ~ 1s
WARN [Thu Aug.

2022-08-11 14:44:48
ErrorException

Undefined array key 1

at D:\xampp\htdocs\laratest\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:289
285protected function getDateFromLine($line)
286▕ {
287preg_match('/^[([^\]]+)]/', $line, $matches);
288▕
➜ 289return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
290▕ }
291292/**
293▕ * Get the request port from the given PHP server output.

PHP server output.

1 D:\xampp\htdocs\laratest\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:289 Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap{closure}("Undefined array key 1", "D:\xampp\htdocs\laratest\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")

2 D:\xampp\htdocs\laratest\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:260 Illuminate\Foundation\Console\ServeCommand::getDateFromLine(" 11 14:44:49 2022] 127.0.0.1:53586 Closing")

Please help :(

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.

© 2025 Laravel.io - All rights reserved.