定位到一行,而不是所有具有特定价值的行 [英] Targeting one row, not all that has a certain value
问题描述
我有一个基本的添加系统,允许房东添加租户,然后租户可以接受/拒绝.接受非常简单,当租户单击接受时,accept布尔值将更改为1.目前,这会将所有行更改为已接受,而不仅仅是房东和租户之间的行.
I have a basic adding system, that allows landlords to add tenants, and tenants then have the ability to accept/reject. Accepting is very simple, when the tenant clicks accept, the accept boolean changes to 1. At the moment this is changeing all rows to accepted, not just the one between the landlord and tenant.
这是数据库中的示例行:
This is an example row in the database:
如果租户单击接受",则接受的行将变为1,并且发送的请求将还原为0.用户现在已连接.
If a tenant clicks accept, the accepted row will change to 1, and request sent will revert to 0. The users are now connected.
但是,所有具有accepted = 0
和request = 1
的行将受到影响,而不仅仅是当前行.
However, all rows that have accepted = 0
, and request = 1
, will be affected, not just the current row.
这是公认的控制器
public function accept(Request $request)
{
Tenancy::where('accepted', 0)
->where('request_sent', 1)
->where('tenant_id', Auth::id())
->update([
'accepted' => 1,
'request_sent' => 0,
]);
return back();
}
有什么想法吗?
编辑
路线URL
Route::post('/account/tenancy/{id}/accept', 'AccountController@accept')->middleware('auth');
接受/拒绝的完整形式和逻辑
Entire form and logic for accept/reject
@if($currentUser->userType == "Tenant")
@if($tenancy == null ||$tenancy->accepted == 0 && $tenancy->request_sent == 1 && $tenancy->tenant_id == $currentUser->id)
<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>
@endif
推荐答案
根据您的评论/最近的修改,我认为这应该可行:
Based on your comments/recent edits, i believe this should work:
全部更改
action="/account/tenancy/{{$user->id}}/accept"
到
action="/account/tenancy/{{$tenancy->id}}/accept"
和您在控制器中的accept/reject
方法,如下所示:
and your accept/reject
methods in the controller like this:
public function accept(Request $request, string $id)
{
Tenancy::find($id)
->update([
'accepted' => 1,
'request_sent' => 0,
]);
return back();
}
这篇关于定位到一行,而不是所有具有特定价值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!