mercredi 2 mai 2018

Different user roles are sent to different profile pages. How can I allow them to view one another

I have two different user types/roles in my system. A landlord, and a tenant. Depending on their type, they are sent to different profile pages. I wan't to provide the landlord an ability to view the tenants page, and the tenant page renders an add button to connect, if they're already connected, and if the request is already sent. I want this on the tenants page, but only the landlord can see it.

Currently page navigaion is done through the id in the url. eg /acount/id

This is the controller that determines where to send a user.

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'));
    }
  }

This is the tenant view page.

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-12">


                
                

            @if(Auth::user()->id != $user->id)
                @if($tenancy == null || $tenantTenancies->accepted == 0 && $tenantTenancies->request_sent === 0)
                    <a href="/account/tenancy//create" class="btn btn-primary">Start Tenancy</a>
                @endif
            @endif

                
                

            @foreach($tenantTenancies as $tenancy)
            <span class="text-muted">You have a request from</span><br>
            <span class="text-muted"><strong>Landlord Name: </strong></span><br>
            <span class="text-muted"><strong>Property Address: </strong></span><br>

            @if(Auth::user()->id == $user->id)
                @if($tenancy != null && $tenancy->accepted == 0 && $tenancy->request_sent == 1)
                    <form method="POST" action="/account/tenancy//accept">
                        
                        <input type="submit" class="btn btn-primary" value="Accept Request">
                    </form>

                    <form method="POST" action="/account/tenancy//reject">
                        
                        <input type="submit" class="btn btn-warning" value="Reject Request">
                    </form>

                    

                @elseif($tenancy != null && $tenancy->accepted == 1 && $tenancy->request_sent == 0)
                    <form method="POST" action="/account/tenancy//end">
                        
                        <input type="submit" class="btn btn-primary" value="End Tenancy">
                    </form>
                @endif
            @endif
            @endforeach
        </div>
        </div>
      </div>
@endsection

Landlord View

@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></span><br>
                <span class="lead"><strong>Property Address: </strong></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/">
                            <img class="list-image img-fluid" src="">
                        </a>
                        <p class="mt-2"></p>
                    </div>
                @endforeach
            </div> <!-- ./col -->
        </div> <!-- ./row -->
    </div>  <!-- ./container -->
@endsection

So when a landlord is viewing the tenant page they should be able to add,check if request is sent, and check if already connected.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2rcBbFG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire