mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 19:51:09 -04:00
init crater
This commit is contained in:
48
app/CompanySetting.php
Normal file
48
app/CompanySetting.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Laraspace;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laraspace\User;
|
||||
|
||||
class CompanySetting extends Model
|
||||
{
|
||||
protected $fillable = ['company_id', 'option', 'value'];
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public static function setSetting($key, $setting, $company_id)
|
||||
{
|
||||
$old = self::whereOption($key)->whereCompany($company_id)->first();
|
||||
|
||||
if ($old) {
|
||||
$old->value = $setting;
|
||||
$old->save();
|
||||
return;
|
||||
}
|
||||
|
||||
$set = new CompanySetting();
|
||||
$set->option = $key;
|
||||
$set->value = $setting;
|
||||
$set->company_id = $company_id;
|
||||
$set->save();
|
||||
}
|
||||
|
||||
public static function getSetting($key, $company_id)
|
||||
{
|
||||
$setting = static::whereOption($key)->whereCompany($company_id)->first();
|
||||
|
||||
if ($setting) {
|
||||
return $setting->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query, $company_id)
|
||||
{
|
||||
$query->where('company_id', $company_id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user