fixed prefix scope

This commit is contained in:
denisdulici
2020-02-09 12:44:36 +03:00
parent 7804fa0859
commit 41cdeae572
10 changed files with 31 additions and 28 deletions

View File

@ -7,7 +7,6 @@ use Illuminate\Database\Eloquent\Model as Eloquent;
class Setting extends Eloquent
{
protected $table = 'settings';
public $timestamps = false;
@ -19,11 +18,6 @@ class Setting extends Eloquent
*/
protected $fillable = ['company_id', 'key', 'value'];
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
@ -31,21 +25,24 @@ class Setting extends Eloquent
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()
{
return $this->belongsTo('App\Models\Common\Company');
}
/**
* Scope to only include by prefix.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param $company_id
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function scopePrefix($query, $prefix = 'company')
{
return $query->where('key', 'like', $prefix . '.%');
}
/**
* Scope to only include company data.
*