-
Notifications
You must be signed in to change notification settings - Fork 554
/
Feature.php
41 lines (34 loc) · 998 Bytes
/
Feature.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace A17\Twill\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Collection;
class Feature extends BaseModel
{
protected $fillable = [
'featured_id',
'featured_type',
'position',
'bucket_key',
'starred',
];
public function featured(): MorphTo
{
return $this->morphTo();
}
public function scopeForBucket(Builder $query, string $bucketKey): Builder
{
return $query->where('bucket_key', $bucketKey)->with('featured');
}
public static function getForBucket(string $bucketKey): Collection
{
return self::forBucket($bucketKey)->get()->map(function (Feature $feature) {
return $feature->featured;
})->filter();
}
public function getTable(): string
{
return config('twill.features_table', 'twill_features');
}
}