我正在處理另一個(gè)人的代碼,當(dāng)我部署 laravel 應(yīng)用程序時(shí),登錄頁面可以工作,但是當(dāng)我輸入測(cè)試憑據(jù)時(shí),它會(huì)拋出此錯(cuò)誤 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實(shí)際引用的函數(shù)如下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 文件中,我認(rèn)為這是調(diào)用方法。我不太熟悉 Laravel,對(duì)于任何菜鳥錯(cuò)誤提前表示歉意。
2 回答

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

Smart貓小萌
TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
我的第一個(gè)猜測(cè),將其更改$user = $this->userRepository->findWithoutFail(auth()->id());
為$user = $this->userRepository->findWithoutFail(auth()->user()->id);
添加auth()->user()->id;
- 2 回答
- 0 關(guān)注
- 218 瀏覽
添加回答
舉報(bào)
0/150
提交
取消