我的系统中有两种不同的用户类型/角色。房东和房客。根据类型,它们会被发送到不同的个人资料页面。我不想为房东提供查看租户页面的能力,并且租户页面呈现添加按钮以进行连接,如果他们已经连接,并且请求是已经发送。我想在租户页面上看到这个,但只有房东可以看到它。
目前,页面导航是通过网址中的ID完成的。例如/ acount / id
这是决定发送用户位置的控制器。
public function index($id){
$user = Auth::user();
//Allows landlords to see their relationship with tenants, and vice versa.
$landlordTenancies = Tenancy::all()->where('landlord_id', Auth::id());
$tenantTenancies = Tenancy::all()->where('tenant_id', Auth::id());
//Sends different use types to relevant view
if($user->userType == "Landlord"){
return view('/pages/account/landlord', compact('user', 'landlordTenancies'));
}
else{
return view('/pages/account/tenant', compact('user', 'tenantTenancies'));
}
}
这是租户视图页面。
@section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
{{-- This blocks a tenant adding themselves --}}
{{-- Shows add button, if tenancy model is empty. Also when no relationship established. --}}
@if(Auth::user()->id != $user->id)
@if($tenancy == null || $tenantTenancies->accepted == 0 && $tenantTenancies->request_sent === 0)
<a href="/account/tenancy/{{$user->id}}/create" class="btn btn-primary">Start Tenancy</a>
@endif
@endif
{{-- Only shows following buttons, if the current signed in user, is the relevant user. --}}
{{-- Shows accept/reject if the request has been sent, but not accepted yet. --}}
@foreach($tenantTenancies as $tenancy)
<span class="text-muted">You have a request from</span><br>
<span class="text-muted"><strong>Landlord Name: </strong>{{$tenancy->landlord_name}}</span><br>
<span class="text-muted"><strong>Property Address: </strong>{{$tenancy->property_address}}</span><br>
@if(Auth::user()->id == $user->id)
@if($tenancy != null && $tenancy->accepted == 0 && $tenancy->request_sent == 1)
<form method="POST" action="/account/tenancy/{{$user->id}}/accept">
{{ csrf_field() }}
<input type="submit" class="btn btn-primary" value="Accept Request">
</form>
<form method="POST" action="/account/tenancy/{{$user->id}}/reject">
{{ csrf_field() }}
<input type="submit" class="btn btn-warning" value="Reject Request">
</form>
{{-- Allows the tenancy to be ended. --}}
@elseif($tenancy != null && $tenancy->accepted == 1 && $tenancy->request_sent == 0)
<form method="POST" action="/account/tenancy/{{$user->id}}/end">
{{ csrf_field() }}
<input type="submit" class="btn btn-primary" value="End Tenancy">
</form>
@endif
@endif
@endforeach
</div>
</div>
</div>
@endsection
业主观点
@section('content')
<div class="container">
<div class="row text-center d-flex flex-wrap">
<div class="col-lg-12">
@foreach($landlordTenancies as $tenancy)
<span class="lead"><strong>Tenant Name: </strong>{{$tenancy->tenant_name}}</span><br>
<span class="lead"><strong>Property Address: </strong>{{$tenancy->property_address}}</span><br>
@endforeach
<h3>Your Active Adverts</h3>
<div class="row py-2">
@foreach ($properties as $property)
<div class="col-md-4 mb-4">
<a href="/property/{{$property->id}}">
<img class="list-image img-fluid" src="{{$property->photo}}">
</a>
<p class="mt-2">{{$property->address .', '. $property->town .', '. $property->county}}</p>
</div>
@endforeach
</div> <!-- ./col -->
</div> <!-- ./row -->
</div> <!-- ./container -->
@endsection
因此,当房东正在查看他们应该能够添加的租户页面时,请检查是否已发送请求,并检查是否已连接。