1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\ModelFilters;
- use App\Models\Asset;
- use Carbon\Carbon;
- use EloquentFilter\ModelFilter;
- class PlanFilter extends ModelFilter
- {
- /**
- * Related Models that have ModelFilters as well as the method on the ModelFilter
- * As [relationMethod => [input_key1, input_key2]].
- *
- * @var array
- */
- public $relations = [];
- public function assetId($assetId): PlanFilter
- {
- $assetIds = Asset::query()->where('path','like','%'.$assetId.'%')->pluck('id');
- if ($assetIds->count() === 1 || $assetIds->isEmpty()) {
- // 如果没有子级,只返回该分组的需求
- return $this->where('asset_id', $assetId);
- }
- return $this->whereIn('asset_id',$assetIds);
- }
- public function expired($expired)
- {
- if (! in_array($expired, ['yes', 'no'])) {
- return $this;
- }
- return $this->when($expired == "yes", function ($query) {
- return $query->where('end', "<=", Carbon::now()->toDateString());
- })->when($expired == "no", function ($query) {
- return $query->where('end', ">", Carbon::now()->toDateString());
- });
- }
- }
|