| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS Product developed. (26.03.19)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ModulesGarden\ProxmoxAddon\App\Models;
- use ModulesGarden\ProxmoxAddon\Core\Models\ExtendedEloquentModel;
- /**
- * @property string $setting
- * @property int $server_id
- * @property string $value
- * @method static ServerConfiguration ofServerId($id)
- * @method static ServerConfiguration ofSetting($setting)
- */
- class ServerConfiguration extends ExtendedEloquentModel
- {
- protected $table = 'ServerConfiguration';
- protected $primaryKey = ['server_id', 'setting'];
- public $incrementing = false;
- /**
- * The attributes that should be cast to native types.
- *
- * @var array
- */
- protected $casts = [
- 'value' => 'array',
- ];
- /**
- * Eloquent fillable parameters
- * @var array
- */
- protected $fillable = ['server_id', 'setting', 'value'];
- public $timestamps = false;
- public function scopeOfServerId($query, $id)
- {
- return $query->where("server_id", $id);
- }
- public function scopeOfSetting($query, $setting)
- {
- return $query->where("setting", $setting);
- }
- public function scopeOfValue($query, $value)
- {
- return $query->where("value", $value);
- }
- /**
- * Set the keys for a save update query.
- *
- * @param \Illuminate\Database\Eloquent\Builder $query
- * @return \Illuminate\Database\Eloquent\Builder
- */
- protected function setKeysForSaveQuery( $query)
- {
- $keys = $this->getKeyName();
- if(!is_array($keys)){
- return parent::setKeysForSaveQuery($query);
- }
- foreach($keys as $keyName){
- $query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
- }
- return $query;
- }
- /**
- * Get the primary key value for a save query.
- *
- * @param mixed $keyName
- * @return mixed
- */
- protected function getKeyForSaveQuery($keyName = null)
- {
- if(is_null($keyName)){
- $keyName = $this->getKeyName();
- }
- if (isset($this->original[$keyName])) {
- return $this->original[$keyName];
- }
- return $this->getAttribute($keyName);
- }
- }
|