akaunting/app/Models/Setting/Setting.php

62 lines
1.2 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Models\Setting;
use App\Scopes\Company;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
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'];
/**
* 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()
{
2018-06-10 02:48:51 +03:00
return $this->belongsTo('App\Models\Common\Company');
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);
}
}