我有一个租户中的两个用户(已连接)。对于一个用户(租户),变量$ tenancy很好并且有数据,但是对于房东来说,它是空的并且调用一个空对象。
This is the database row (fake data)
呈现配置文件的控制器代码是
public function index($id){
//Authenticated different user types
//Sends Landlord and Tenant to appropiate pages
$user = User::where('id', $id)->first();
$tenancy = Tenancy::where('tenant_id', Auth::id())->first();
if($user->userType == "Landlord")
{
return view('/pages/account/landlord', compact( 'user', 'tenancy'));
}
else
{
return view('/pages/account/tenant', compact('user', 'tenancy'));
}
}
在租户视图页面上,我可以像这样调用数据
<span class="lead"><strong>Landlord Name: </strong>{{$tenancy->landlord_name}}</span><br>
<span class="lead"><strong>Property Address: </strong>{{$tenancy->property_address}}</span><br>
<span class="lead"><strong>Tenant Name: </strong>{{$tenancy->tenant_name}}</span><br>
但是在房东页面上,我收到以下错误
尝试获取非对象的属性