Laravel雄辩 - >方法不存在。但它是在模型中定义的

时间:2018-05-05 19:03:54

标签: laravel eloquent blade

我试图减少视图中的逻辑数量。所以我正在创建方法,而是调用它。

用户模型有这两种方法。

它可以找到inTenancy就好了:

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

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

这是我的控制器,我无法拨打requestPending,但我可以致电inTenancy,即使他们在同一个地方。

有什么想法吗?

@if($tenancy->requestPending())
    <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>

@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

0 个答案:

没有答案