public function block()
{
@($id = (int) \Route::input('id'));
$response = ['state' => 'error', 'message' => 'Something wrong.'];
if (!empty($id) && $id > 0) {
$post = \DB::table('post')->where('id', $id)->first();
if (count($post) > 0) {
$ip = $post->post_user_ip;
$check = \DB::table('block_guest')->where('ip', $ip)->first();
if (count($check) > 0) {
$response = ['state' => 'success', 'message' => 'Data exist.'];
} else {
if (\DB::table('block_guest')->insert(['ip' => $ip])) {
$response = ['state' => 'success', 'message' => 'Block success.'];
} else {
$response = ['state' => 'failed', 'message' => 'Block failed.'];
}
}
}
}
echo json_encode($response);
}