akaunting/app/Models/Setting/Setting.php
Denis Duliçi 1d51b61821 formatting
2021-02-26 17:31:02 +03:00

71 lines
1.5 KiB
PHP

<?php
namespace App\Models\Setting;
use App\Traits\Tenants;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Setting extends Eloquent
{
use Tenants;
protected $table = 'settings';
protected $tenantable = true;
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'key', 'value'];
public $allAttributes = [];
public $timestamps = false;
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public function company()
{
return $this->belongsTo('App\Models\Common\Company');
}
/**
* Scope to only include by prefix.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $prefix
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePrefix($query, $prefix = 'company')
{
return $query->where('key', 'like', $prefix . '.%');
}
/**
* 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);
}
}