我有
{% if auth.renderFriendShip("{{auth.id}}", "{{user.id}}", 'isThereFriendship') == 0 %}
在我的视图文件中。它应该改变 {{auth.id}} 和 {{user.id}},但事实并非如此。当我在我的 php 模型中的 {{user.id}} 上运行“var_dump”时(函数通向)......它只输出 {{user.id}}。
这是我的视图文件中的相关代码...
{% if auth.renderFriendShip("{{auth.id}}", "{{user.id}}", 'isThereFriendship') == 0 %}
<button class="friendBtn add" data-uid="{{user.id}}" data-type="addFriend">Friend</button>
<button class="request_pending hidden" disabled>Request Pending</button>
{% else %}
<button class="friendBtn unfriend" data-uid="{{user.id}}" data-type="unfriend">Unfriend</button>
<button class="friendBtn add hidden" data-uid="{{user.id}}" data-type="addFriend">Add as friend</button>
<button class="request_pending hidden" disabled>Request Pending</button>
{% endif %}
和我的用户模型...
public function renderFriendShip($user_one, $user_two, $type) {
if(!empty($user_one) || !empty($user_two) || !empty($type)) {
switch($type) {
case 'isThereRequestPending':
$matchThese = ['user_one' => "$user_one", 'user_two' => "$user_two", 'friendship_official' => '0'];
$orMatchThese = ['user_one' => "$user_two", 'user_two' => "$user_one", 'friendship_official' => '0'];
$query = $this->friendsList()
->where($matchThese)
->orWhere($orMatchThese)
->get()
->count();
return $query;
break;
case 'isThereFriendship':
$q = $this->friendsList()
->where(function($query) use ($user_one, $user_two) {
return $query->where(['user_one' => $user_one, 'user_two' => $user_two, 'friendship_official' => '1']);
})
->orWhere(function($query) use ($user_one, $user_two) {
return $query->where(['user_one' => $user_two, 'user_two' => $user_one, 'friendship_official' => '1']);
})
->get()
->count();
break;
}
return var_dump($user_two);
} else {
return "Failed";
}
}
谢谢你能给我的任何建议。我一直在寻找几个小时,但我还没有找到解决方案。