Closed lloy0076 closed 4 years ago
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.