尝试仅在服务器上获取非对象的 属性 'full_name'

Trying to get property 'full_name' of non-object on server only

这很奇怪。我在本地主机上的代码 运行 正常,但在我的数字海洋服务器上抛出错误。这是我的代码;

Provide.php

public function user()
{
    return $this->belongsTo('App\Models\User', 'user_id', 'id');
}

在我的控制器中。 ProvideController.php

 $helper = ProvideHelp::where('id', 1)->first();

在我看来我有

<tr>
   <th scope="row">Amount</th>
   <td>₦{{ $helper->amount }}</td>
</tr>
<tr>
  <th scope="row">Name</th>
  <td>{{ $helper->user->full_name }}</td>
</tr>
<tr>
<th scope="row"> Phone Number</th>
    <td>{{ $helper->user }}</td>
 </tr>

在本地它工作正常但在我的服务器上我收到以下错误

Trying to get property 'full_name' of non-object 

如果能指出为什么会这样,我将不胜感激

试试这个:

$helper = ProvideHelp::with('user')->where('id', 1)->first();