'bool', 'is_free' => 'bool', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { // * EVENT CLOSURES. static::creating(function (self $model) { throw new \RuntimeException("Creating {$model->id} is not allowed", 1); }); static::created(function (self $model) { self::flashStatus($model); }); static::updated(function (self $model) { Cache::delete('DeliveryModesGlobal'); self::flashStatus($model, true); }); static::deleting(function (self $model) { throw new \RuntimeException("Deleting {$model->id} is not allowed", 1); }); } // * METHODS /** * Getter mode * * @return \App\Enums\DeliveryMode\DeliveryModeEnum */ public function getModeAttribute(): DeliveryModeEnum { return DeliveryModeEnum::make(\intval($this->id)); } /** * Query available delivery Methods * * @return Builder */ public static function availables(): Builder { return self::where('status', true); } // * - Cache /** * Get all available delivery modes from cache. * If cache was reset, it will fetch them from DB. * * @return \Illuminate\Database\Eloquent\Collection */ public static function getCachedDeliveryModes() { if (!Cache::has('DeliveryModesGlobal')) { self::setCachedDeliveryModes(); } return Cache::get('DeliveryModesGlobal'); } /** * Put all available delivery modes into cache. * * @return void */ protected static function setCachedDeliveryModes(): void { Cache::put('DeliveryModesGlobal', self::all()); } }