123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Repositories\Models;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Support\Traits\SerializeDate;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model as EloquentModel;
- use Illuminate\Support\Facades\App;
- use Jenssegers\Mongodb\Eloquent\SoftDeletes;
- abstract class Model extends EloquentModel
- {
- use SerializeDate;
- use SoftDeletes;
- protected $hidden = ['deleted_at'];
- protected static function language()
- {
- $language = request()->header('language', App::getLocale());
- // $language = 'zh_CN';
- switch ($language) {
- case 'zh_CN':
- default:
- $language = 'zh_CN';
- break;
- case 'en':
- $language = 'en';
- break;
- }
- static::addGlobalScope('language', function (Builder $builder) use ($language) {
- $builder->where('language', $language);
- });
- static::creating(function ($model) use ($language) {
- if (!(in_array('language', array_keys($model->attributes)) && !empty($model->attributes['language']))) {
- $model->language = $language;
- }
- });
- }
- public function scopeStatus($query)
- {
- return $query->where('status', ModelStatusEnum::OK);
- }
- }
|