Beispiel #1
0
 /**
  * Get values from lookups table
  * and store it in cache to fix N+1 problem
  *
  * @return string
  * @author Gat
  **/
 public static function getLookupValue($key, $id)
 {
     if (Cache::has("{$key}_{$id}")) {
         return Cache::get("{$key}_{$id}");
     }
     $lookupValue = Lookups::whereKey($key)->whereKeyId($id)->first()->value;
     // Set expiry for 1 day
     $duration = Carbon::now()->addDay();
     // Store in cache
     Cache::put("{$key}_{$id}", $lookupValue, $duration);
     return $lookupValue;
 }