Passed
Pull Request — master (#194)
by
unknown
14:54
created

BlogEtcPublishedScope::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 4
b 1
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace WebDevEtc\BlogEtc\Scopes;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Scope;
9
use WebDevEtc\BlogEtc\Helpers;
10
11
class BlogEtcPublishedScope implements Scope
12
{
13
    /**
14
     * Only show posts which are published in the past, unless the user has admin access.
15
     */
16
    public function apply(Builder $builder, Model $model)
17
    {
18
        if (Helpers::hasAdminGateAccess()) {
19
            return;
20
        }
21
22
        $builder->where('is_published', true);
23
        $builder->where('posted_at', '<=', Carbon::now());
24
    }
25
}
26