akaunting/app/Models/Setting/Setting.php

83 lines
1.8 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Models\Setting;
2020-05-02 14:33:41 +03:00
use App\Traits\Tenants;
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
{
2020-05-02 14:33:41 +03:00
use Tenants;
2017-09-14 22:21:00 +03:00
protected $table = 'settings';
2021-01-19 17:36:39 +03:00
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'key', 'value'];
2021-02-26 17:31:02 +03:00
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);
}
/**
* Update the model in the database.
*
* @param array $attributes
* @param array $options
* @return bool
*/
public function update(array $attributes = [], array $options = [])
{
$this->allAttributes = $attributes;
return parent::update($attributes, $options);
}
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
2020-02-14 15:08:16 +03:00
* @param string $prefix
2020-02-09 12:44:36 +03:00
*
* @return \Illuminate\Database\Eloquent\Builder
2017-09-14 22:21:00 +03:00
*/
2020-02-09 12:49:46 +03:00
public 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);
}
}