/**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Validator::extend('sms', function ($attribute, $value, $parameters) {
         try {
             $sms = Sms::where('to', $value)->orderBy('id', 'desc')->firstOrFail();
             $dt = Carbon::now();
             $sentTime = Carbon::createFromTimestamp($sms->sent_time);
             $second = $dt->diffInSeconds($sentTime);
             if ($second < 40) {
                 return false;
             }
             return true;
         } catch (ModelNotFoundException $e) {
             return true;
         }
     });
     Validator::extend('mobile', function ($attribute, $value, $parameters) {
         return preg_match('/^1[3|4|5|7|8|][0-9]{9}$/', $value);
     });
     Validator::extend('verify_code_mock', function ($attribute, $value, $parameters) {
         $smsData = \SmsManager::getSmsDataFromSession();
         if ($smsData && $smsData['deadline_time'] >= time() && $smsData['code'] == $value || $value == '8888') {
             return true;
         }
         return false;
     });
 }
Example #2
0
<?php

Validator::extend('mobile', function ($attribute, $value, $parameters) {
    return preg_match('/^1[3|5|7|8|][0-9]{9}$/', $value);
});
Validator::extend('mobile_changed', function ($attribute, $value, $parameters) {
    $smsData = SmsManager::getSmsDataFromSession();
    if ($smsData && $smsData['mobile'] == $value) {
        return true;
    }
    return false;
});
Validator::extend('verify_code', function ($attribute, $value, $parameters) {
    $smsData = SmsManager::getSmsDataFromSession();
    if ($smsData && $smsData['deadline_time'] >= time() && $smsData['code'] == $value) {
        return true;
    }
    return false;
});
Validator::extend('verify_rule', function ($attribute, $value, $parameters) {
    $smsData = SmsManager::getSmsDataFromSession();
    if ($smsData && $smsData['verify']['mobile']['choose_rule'] == $parameters[0]) {
        return true;
    }
    return false;
});