나는 차단 된 사용자라고 불리는이 테이블을 가지고 있으므로 그렇게 배치되어있다.Laravel Model, 이것을 수정하는 깔끔한 방법
id, user_id, blocked_user_id, reason, created_at, updated_at
이제 2 명이 대화 할 수있는 메시지 컨트롤러가 있습니다. 내가 그런 식으로 메시지를 보내기 전에 사용자 차단 여부를 확인하고 싶습니다.
$blkchk = $thread->participants()->withTrashed()->get();
foreach ($blkchk as $usr) {
$usrs[] = $usr->user_id;
}
$block = BlockedUsers::where('user_id',$usrs[0])->where('blocked_user_id', $usrs[1])->first();
$block2 = BlockedUsers::where('user_id',$usrs[1])->where('blocked_user_id', $usrs[0])->first();
if (!empty($block) || !empty($block2)) {
return response()->view('errors.403', ['error' => 'One of the users in this conversation is blocked.'], 404);
}
이것은 꽤 엉망이지만 blkchk는 대화에서 두 사용자 ID를 얻습니다. 배열로 설정 한 다음 개별적으로 각각을 대상으로합니다. 완벽하게 작동하지만 Verry 지저분하다고 생각합니다.
이 작업을 수행하는 방법이 정확하고 깔끔한 방법 일지 궁금합니다.
이것이 작동하는 코드 인 경우 http://codereview.stackexchange.com/ – phaberest