Exemplo n.º 1
0
 /**
  * @param Carbon $now
  * @param string $externalApiName
  * @param int    $externalApiLimit
  * @param string $externalApiLimitInterval
  *
  * @return mixed
  */
 public function addExternalAPILimitCounter(Carbon $now, $externalApiName = 'test', $externalApiLimit = 100000, $externalApiLimitInterval = 'Day')
 {
     $ExternalApiLimit = ExternalApiLimit::where('external_api_name', $externalApiName)->where('external_api_limit_interval', $externalApiLimitInterval)->where('limit_interval_start', '<=', $now->toDateTimeString())->where('limit_interval_end', '>=', $now->toDateTimeString())->first();
     if (empty($ExternalApiLimit)) {
         $ExternalApiLimit = new ExternalApiLimit();
         $ExternalApiLimit->external_api_name = $externalApiName;
         $ExternalApiLimit->external_api_limit_interval = $externalApiLimitInterval;
         $ExternalApiLimit->external_api_limit = $externalApiLimit;
         $StartEnd = ExternalApiLimit::convertIntervalStringToStartEnd($externalApiLimitInterval, $now);
         $ExternalApiLimit->limit_interval_start = $StartEnd['limit_interval_start'];
         $ExternalApiLimit->limit_interval_end = $StartEnd['limit_interval_end'];
     }
     $ExternalApiLimit->external_api_count = $ExternalApiLimit->external_api_count + 1;
     $ExternalApiLimit->save();
     return $ExternalApiLimit->external_api_limit_left;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $title = 'External Api Limits';
     $externalApiLimits = ExternalApiLimit::where('limit_interval_start', '>', Carbon::now()->subDays(31))->orderBy('limit_interval_start', 'desc')->get();
     return view('admin.dashboard.ExternalApiLimit.ExternalApiLimitList', compact('title', 'externalApiLimits'));
 }