123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Model;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- class Company extends Model
- {
- /**
- * @var string
- */
- protected $table = 'base_departments';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- /***
- * 根据id获取对象
- * @param $id
- * @return mixed
- */
- public static function byId($id)
- {
- return Cache::remember('model:company:byId:' . $id, Carbon::now()->addDays(1), function () use ($id) {
- return self::query()->where('id', $id)->where('status', ModelStatusEnum::OK)->first();
- });
- }
- }
|