Setting.php
1.24 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
61
<?php
namespace App\Models\Setting;
use App\Scopes\Company;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
protected $table = 'settings';
public $timestamps = false;
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'key', 'value'];
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope(new Company);
}
public static function all($code = 'general')
{
return static::where('key', 'like', $code . '.%')->get();
}
/**
* Global company relation.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function company()
{
return $this->belongsTo('App\Models\Common\Company');
}
/**
* Scope to only include company data.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param $company_id
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCompanyId($query, $company_id)
{
return $query->where($this->table . '.company_id', '=', $company_id);
}
}