FupingQiu / okrsw

0 stars 0 forks source link

Undefined index array offset #6

Closed FupingQiu closed 6 years ago

FupingQiu commented 6 years ago

发现在repository下,无法获得object的field内容。 if ($annualObject['progress'] != 2){ Log::info(CLASS . '::' .FUNCTION . ' : ' . 'id = ' . $id . ', progress = ' . $annualObject['progress']); if (request()->wantsJson()) { return response()->json([ 'error' => true, 'message' => '目标不在未开始状态,不可删除' ]); } return redirect()->back()->withErrors('目标不在未开始状态,不可删除')->withInput();
}

提示 [2018-08-10 11:35:45] testing.ERROR: Undefined index: progress {"userId":1,"email":"armando.balistreri@example.net","exception":"[object] (ErrorException(code: 0): Undefined index: progress at D:\laragon\www\OKRsWalking\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1779) [stacktrace]

0 D:\laragon\www\OKRsWalking\vendor\laravel\framework\src\Illuminate\Support\Collection.php(1779): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', 'D:\\laragon\\www\\...', 1779, Array)

1 D:\laragon\www\OKRsWalking\app\Http\Controllers\AnnualObjectsController.php(398): Illuminate\Support\Collection->offsetGet('progress')

2 [internal function]: App\Http\Controllers\AnnualObjectsController->destroy('4')

FupingQiu commented 6 years ago

注意$annualObject [{"id":8,"annual_object":"\u7ee2\u82cf\u7532\u77e2\u5e55\u5531\u53d9\u4f20\u6cdb\u9ed1\u7597\u60df\u8c0b\u52c3\u79c0\u9a91\u5185\u7ecf\u9986\u9b44\u576a\u6454\u5929\u58eb\u950c\u8bb8\u5395\u8f88\u59d0\u4e3a\u8113\u5321\u51e4\u79e6\u575d\u6797\u5fb7\u5450\u5c3d\u75b5\u7470\u9f3b\u73a9","importance":1,"urgency":1,"plan_duration":2,"progress":3,"begin_time":"2018-08-10 16:22:26","end_time":"2018-08-10 16:22:26","field_first_id":null,"field_second_id":null,"field_third_id":null,"activities_amount":0,"actual_time_spent":0,"average_score":0,"user_id":1,"deleted_at":null,"created_at":"2018-08-10 12:17:31","updated_at":"2018-08-10 16:22:26"}]

正确获取方法为,$annualObject[0][...]