forked from slimkit/plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonConfig.php
More file actions
60 lines (53 loc) · 1.6 KB
/
Copy pathCommonConfig.php
File metadata and controls
60 lines (53 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Zhiyi\Plus\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class CommonConfig extends Model
{
protected $primaryKey = ['name', 'namespace'];
public $incrementing = false;
protected $fillable = ['name', 'namespace', 'value'];
/**
* Scope func to namespace.
*
* @param Illuminate\Database\Eloquent\Builder $query
* @param string $namespace
*
* @return Illuminate\Database\Eloquent\Builder
*
* @author Seven Du <shiweidu@outlook.com>
* @homepage http://medz.cn
*/
public function scopeByNamespace(Builder $query, string $namespace): Builder
{
return $query->where('namespace', $namespace);
}
/**
* Scope func to name.
*
* @param Illuminate\Database\Eloquent\Builder $query
* @param string $name
*
* @return Illuminate\Database\Eloquent\Builder
*
* @author Seven Du <shiweidu@outlook.com>
* @homepage http://medz.cn
*/
public function scopeByName(Builder $query, string $name): Builder
{
return $query->where('name', $name);
}
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
foreach ($this->getKeyName() as $key) {
$query->where($key, '=', $this->original[$key] ?? $this->getAttribute($key));
}
return $query;
}
}