vendredi 27 avril 2018

Created a friend request system, error if there isn't already data in the database

I created a "Friend System" for Landlord to add a tenant to start a tenancy and allow the tenant accept the request. It works almost perfectly.

If there is no data in the database, the landlord can't view the tenant profile to add them, as there are no objects in the database.

The error is

Trying to get property of non-object

This points to the second if statement, and works it's way down as you delete the section of the if statement.

How do I show the start tenancy button, if the objects are null

This is the code

  @if($user->userType != "Landlord")
    <div class="row">
      <!-- 
        If the request hasn't been sent, and hasn't been excepted.
        Provie button to send a tenancy request
      -->
      @if($Tenancy->accepted == 0 && $Tenancy->request_sent != 1)
        <a href="/account/tenancy//create" class="btn btn-primary">Start Tenancy</a>
          <!-- 
            If the user signed in, isn't the owner of this profile.
            Do not show these buttons that control accept/reject/end
          -->
          @if(Auth::user() != $user->id)
            <!-- 
              If the request has been sent, but hasn't been accepted.
              Give option to accept and reject.
              This updates the values in DB.
            -->
            @elseif($Tenancy->accepted == 0 && $Tenancy->request_sent == 1)
              <form method="POST" action="/account/tenancy//accept">
                
                <button class="btn btn-primary" value="Accept Request"></button>
              </form>
              <form method="POST" action="/account/tenancy//reject">
                
                <button class="btn btn-warning" value="Reject Request"></button>
              </form>
              <!-- 
                If the request has been accepted.
                Show button to end the tenancy,
                and property details
              -->
            @elseif($Tenancy->accepted == 1 && $Tenancy->request_sent == 0)
              <form method="POST" action="/account/tenancy//accept">
                
                <button class="btn btn-primary" value="End Tenancy"></button>
              </form>
                <h5>Currently in Tenancy with </h5>
                <h5>Your property is </h5>
          @endif <!-- End of current user vs this user-->
      @endif <!-- Initial If-->
    </div>



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

Aucun commentaire:

Enregistrer un commentaire