ActiveableScope::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
4
namespace Alish\ActiveableModel\Scopes;
5
6
use Alish\ActiveableModel\Models\ActiveableModel;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Model;
9
use Illuminate\Database\Eloquent\Scope;
10
11
class ActiveableScope implements Scope
12
{
13
14
    public function apply(Builder $builder, Model $model)
15
    {
16
        $builder->addSelect([
17
            'is_active' => ActiveableModel::select('is_active')
18
                ->whereColumn('object_id', $model->getTable() . ".id")
19
                ->where('object_type', get_class($model))
20
                ->latest('created_at')
21
                ->latest('id')
22
                ->limit(1)
23
        ]);
24
    }
25
26
27
}
28