2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Setting;
|
|
|
|
|
|
|
|
use App\Scopes\Company;
|
2019-11-16 10:21:14 +03:00
|
|
|
use Illuminate\Database\Eloquent\Model as Eloquent;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
class Setting extends Eloquent
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
|
|
|
protected $table = 'settings';
|
|
|
|
|
2018-01-10 18:21:12 +03:00
|
|
|
public $timestamps = false;
|
|
|
|
|
2017-09-14 22:21:00 +03:00
|
|
|
/**
|
|
|
|
* Attributes that should be mass-assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = ['company_id', 'key', 'value'];
|
|
|
|
|
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::addGlobalScope(new Company);
|
|
|
|
}
|
|
|
|
|
2020-02-09 12:44:36 +03:00
|
|
|
public function company()
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2020-02-09 12:44:36 +03:00
|
|
|
return $this->belongsTo('App\Models\Common\Company');
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-09 12:44:36 +03:00
|
|
|
* Scope to only include by prefix.
|
2017-09-14 22:21:00 +03:00
|
|
|
*
|
2020-02-09 12:44:36 +03:00
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
|
|
* @param $company_id
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
2017-09-14 22:21:00 +03:00
|
|
|
*/
|
2020-02-09 12:44:36 +03:00
|
|
|
public static function scopePrefix($query, $prefix = 'company')
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2020-02-09 12:44:36 +03:00
|
|
|
return $query->where('key', 'like', $prefix . '.%');
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|