为了账号安全,请及时绑定邮箱和手机立即绑定

laravel 尝试获取非对象错误的属性“id”

laravel 尝试获取非对象错误的属性“id”

PHP
米脂 2023-06-30 16:29:55
我正在处理另一个人的代码,当我部署 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条经验 获得超3个赞

你必须改变这一行

$user = $this->userRepository->findWithoutFail(auth()->id());

$user = $this->userRepository->findWithoutFail(auth()->user()->id());


查看完整回答
反对 回复 2023-06-30
?
Smart猫小萌

TA贡献1911条经验 获得超7个赞

我的第一个猜测,将其更改$user = $this->userRepository->findWithoutFail(auth()->id());$user = $this->userRepository->findWithoutFail(auth()->user()->id);

添加auth()->user()->id;


查看完整回答
反对 回复 2023-06-30
  • 2 回答
  • 0 关注
  • 161 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信