Laravel 6.X | Undefined Offset Bug?
Closed this issue · 5 comments
[
{
"id": 1,
"testCamelCase": "Camel Case",
"testSnakeCase": null,
"test_snake_case": "Snake Case"
}
]
{
"message": "Undefined offset: 1",
"exception": "ErrorException",
"file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\AbstractLogger.php",
"line": 48,
"trace": [
{
"file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\AbstractLogger.php",
"line": 48,
"function": "handleError",
"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
"type": "->"
},
{
"file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\DBLogger.php",
"line": 33,
"function": "logData",
"class": "AWT\\AbstractLogger",
"type": "->"
},
{
"file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\Http\\Middleware\\ApiLogger.php",
"line": 30,
"function": "saveLogs",
"class": "AWT\\DBLogger",
"type": "->"
},
{
"file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
"line": 218,
"function": "terminate",
"class": "AWT\\Http\\Middleware\\ApiLogger",
"type": "->"
},
{
"file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
"line": 189,
"function": "terminateMiddleware",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "C:\\laragon\\webroots\\current\\laravel-six\\public\\index.php",
"line": 60,
"function": "terminate",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
}
]
}```
I caused that with the attached file in routes/api.php
on Laravel 6.
Route::any('v1/test',
'TestController',
function (Request $request) {
$results = [];
$tests = [
[
'id' => 1,
'testCamelCase',
],
];
$result =
[
'id' => 1,
'testCamelCase' => 'testCamelCase',
'testSnakeCase' => 'testSnakeCase',
'test_snake_case' => 'test_snake_case',
];
Log::debug(__FILE__, [$result]);
$results[] = $result;
return response()->json($results, 200);
}
)->name('api.test')->middleware('apilogger');
The file, zipped:
The composer.install, zipped:
The offending line is https://github.com/aungwinthant/apilogger/blob/master/src/AbstractLogger.php#L48
if($currentRouteAction){
list($controller,$action) = explode('@',$currentRouteAction);
}
We shouldn't assume that a route has a @
.
Let's say we have this:
Route::any('/test', 'TestController')->name('test');
This is valid because the TestController
may have an __invoke
as per https://laravel.com/docs/6.x/controllers#single-action-controllers
Or we just put the route into the route file as a closure as above.
Ah, I see. This is a bug for sure and it is my bad. I completely forgot about single action controllers. I will update the package with better testing soon.
@aungwinthant I've put together a fix that at least stops a complete crash and I now see:
Oops, I was cowboy coding and took out some important code.