Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andremac96's avatar

Error method does not exist, but other methods are being found.

Hi

I have posted a few times, but i'm getting this weird error.

I have 3 methods in my Tenancy Model

//Helper method to clean up Tenancy/index
public function notInTenancy()
{
    return $this->accepted == 0 && $this->request_sent == 0;
}

public function hasRequestPending()
{
    return $this->accepted == 0 && $this->request_sent == 1;
}


public function inTenancy()
{
    return $this->accepted == 1 && $this->request_sent == 0;
}

hasRequestPending is not being recognized in the view, but the other two are. My error is

Method hasRequestPending does not exist. (View:

The methods are being passed in the controller via the $Tenancy variable

public function index($id){

   $user = User::where('id', $id)->first();

   $Tenancy = Tenancy::where('tenant_id', Auth::id())->get();


  return view('/pages/account/index', compact('user', 'Tenancy'));
}

In my views they're being called like so

@if(Auth::user()->id == $user->id)

You cannot add yourself

@elseif($Tenancy == null || $Tenancy->notInTenancy()) Start Tenancy @endif

      {{--  
        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()->id == $user->id)
      {{-- 
        If the request has been sent but hasn't been accepted.
        Give the option to accept and reject.
        This updates the values in DB.
      --}}

      @if($Tenancy->hasRequestPending())
      
      
        <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>
          <!-- 
            If the request has been accepted.
            Show button to end the tenancy,
            and property details
          -->
      @elseif($Tenancy->inTenancy())
        <form method="POST" action="/account/tenancy/{{$user->id}}/end">
          {{ csrf_field() }}
          <input type="submit" class="btn btn-primary" value="End Tenancy">
        </form>
        <h5>Currently in Tenancy with {{$Tenancy->landlord_name}}</h5>
        <h5>Your property is {{$Tenancy->property_address}}</h5>
      @endif <!-- End of current user vs this user-->
    @endif <!-- Initial If-->

The first method and third method are recognized, but number 2, is not.

0 likes
4 replies
bobbybouwmann's avatar

Your code looks correct! Can you try to clear your class cache by running

php artisan clear-compiled

I recommend you to work with lowercase variables, because this uppercase variable is really unreadable and annoying to me :P

1 like
andremac96's avatar

Nope still the same. Would it be something to do with boolean entries in the database?

bobbybouwmann's avatar

Well that has nothing to do with the object! Are you sure $Tenancy is a model object here and not just an empty object?

1 like
andremac96's avatar

I change $Tenancy to $Tenancy = Tenancy::all();

A dd on that results in an output of the following

https://imgur.com/a/MUv7kQh

Which is the entry in the database?

But it still isn't finding the method.

Please or to participate in this conversation.