我正在處理另一個人的代碼,當我部署 laravel 應用程序時,登錄頁面可以工作,但是當我輸入測試憑據時,它會拋出此錯誤 Trying to get property 'id' of non-object in helpers.php line 159 at HandleExceptions->handleError(8, 'Trying to get property \'id\' of non-object', '/var/www/html/first-project/app/Helpers/helpers.php', 159, array('fields' => object(Collection), 'fieldsValues' => object(Collection), 'htmlFields' => array(), 'startSeparator' => '<div style="flex: 50%;max-width: 50%;padding: 0 4px;" class="column">', 'endSeparator' => '</div>', 'field' => object(CustomField), 'dynamicVars' => array('$RANDOM_VARIABLE$' => 'var15931958241638660037ble', '$FIELD_NAME$' => 'phone', '$DISABLED$' => '', '$REQUIRED$' => '"required" => "required",', '$MODEL_NAME_SNAKE$' => 'user', '$FIELD_VALUE$' => '\'+136 226 5660\'', '$INPUT_ARR_SELECTED$' => '+136 226 5660'), 'gf' => object(GeneratorField), 'value' => object(CustomFieldValue))) in helpers.php line 159實際引用的函數如下function generateCustomField($fields, $fieldsValues = null){ $htmlFields = []; $startSeparator = '<div style="flex: 50%;max-width: 50%;padding: 0 4px;" class="column">'; $endSeparator = '</div>'; foreach ($fields as $field) { $dynamicVars = [ '$RANDOM_VARIABLE$' => 'var' . time() . rand() . 'ble', '$FIELD_NAME$' => $field->name, '$DISABLED$' => $field->disabled === true ? '"disabled" => "disabled",' : '', '$REQUIRED$' => $field->required === true ? '"required" => "required",' : '', '$MODEL_NAME_SNAKE$' => getOnlyClassName($field->custom_field_model), '$FIELD_VALUE$' => 'null', '$INPUT_ARR_SELECTED$' => '[]', ];它在控制器中的用法如下。它在幾乎所有控制器中多次使用,例如在 UserController.php 文件中,我認為這是調用方法。我不太熟悉 Laravel,對于任何菜鳥錯誤提前表示歉意。
2 回答

守著一只汪
TA貢獻1872條經驗 獲得超4個贊
你必須改變這一行
從
$user = $this->userRepository->findWithoutFail(auth()->id());
到
$user = $this->userRepository->findWithoutFail(auth()->user()->id());

Smart貓小萌
TA貢獻1911條經驗 獲得超7個贊
我的第一個猜測,將其更改$user = $this->userRepository->findWithoutFail(auth()->id());
為$user = $this->userRepository->findWithoutFail(auth()->user()->id);
添加auth()->user()->id;
- 2 回答
- 0 關注
- 220 瀏覽
添加回答
舉報
0/150
提交
取消