本文整理汇总了PHP中Phone::withTrashed方法的典型用法代码示例。如果您正苦于以下问题:PHP Phone::withTrashed方法的具体用法?PHP Phone::withTrashed怎么用?PHP Phone::withTrashed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phone
的用法示例。
在下文中一共展示了Phone::withTrashed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: auth
/**
* @return \Illuminate\Http\JsonResponse
*/
public function auth()
{
//TODO rate limit
//TODO Validation
$udid = Input::get('udid');
$phone = Input::get('phone');
if (strlen($phone) < 9) {
return $this->respondInsufficientPrivileges('Номер телефона слишком короткий');
}
if (intval($phone[2]) == 0) {
return $this->respondInsufficientPrivileges('Вы пытаетесь зарегистрировать несуществующий номер.');
}
$providerCode = intval($phone[0] . $phone[1]);
if (!in_array($providerCode, [99, 50, 51, 55, 70, 77])) {
return $this->respondInsufficientPrivileges('Таких операторов не существует.');
}
$type = Input::has('type') ? Input::get('type') : 'verify';
$phoneModel = Phone::withTrashed()->where('number', $phone)->first();
if ($phoneModel && $type != 'reset') {
if (!$phoneModel->deleted_at) {
return $this->respondInsufficientPrivileges("Номер занят");
}
if (Carbon::now()->lte(Carbon::parse($phoneModel->deleted_at)->addDays(30))) {
$allowedTime = Carbon::parse($phoneModel->deleted_at)->addDays(30);
return $this->respondInsufficientPrivileges("Данный номер телефона не доступен для регистрации до {$allowedTime}");
}
}
if ($type == 'changePhone') {
if ($phoneModel) {
return $this->respondInsufficientPrivileges("Number is already occupied");
}
$header = Request::header('Authorization');
if (is_null($header)) {
return $this->respondInvalidApi('Unauthorized');
}
if (!isset(explode(' ', $header)[1])) {
return $this->respondInvalidApi('Unauthorized');
}
$token = explode(' ', $header)[1];
if ($token) {
$device = Device::where('auth_token', $token)->orderBy('id', 'desc')->first();
$user = $device->user;
if (!$user->checkPasswordAttribute(Input::get('password'))) {
return $this->respondInsufficientPrivileges('Wrong password');
}
}
}
if (!$phoneModel && $type == 'reset') {
return $this->respondInsufficientPrivileges('Number not found');
}
$tempSMS = SMS::where('device', $udid)->where('phone', $phone)->orderBy('id')->first();
if ($tempSMS) {
$minTime = Carbon::parse($tempSMS->sent_at)->addMinutes(3);
$maxTime = Carbon::parse($tempSMS->sent_at)->addHour();
if ($tempSMS->verified) {
if (Carbon::now()->lte($maxTime)) {
return $this->respond(['status' => 3, 'token' => $tempSMS->token]);
}
}
if (Carbon::now()->lte($minTime)) {
return $this->respond(['message' => 'Please wait ' . Carbon::now()->diffInSeconds($minTime) . ' seconds', 'timeout' => Carbon::now()->diffInSeconds($minTime), 'token' => $tempSMS->token, 'status' => 2]);
}
$tempSMS->code = rand(1000, 10000);
$tempSMS->sent_at = Carbon::now()->toDateTimeString();
// TODO Send sms
$smsSender = new smsSender(fetchNumber($phone), $tempSMS->code);
$smsSender->send(function ($res) {
// dd($res->xml());
});
$tempSMS->save();
return $this->respond(['timeout' => 180, 'token' => $tempSMS->token, 'status' => 2]);
} else {
$code = rand(1000, 10000);
$newSMSEntry = SMS::create(['phone' => $phone, 'code' => $code, 'token' => base64_encode(openssl_random_pseudo_bytes(32)), 'device' => $udid, 'sent_at' => Carbon::now()->toDateTimeString()]);
}
//TODO Send an SMS
$smsSender = new smsSender(fetchNumber($phone), $code);
$smsSender->send(function ($res) {
// dd($res->xml());
});
//SMS Logic
if (isset($newSMSEntry)) {
return $this->respond(['timeout' => 180, 'token' => $newSMSEntry->token, 'status' => 2]);
}
return $this->respondServerError('Something went wrong');
}