BlogCommentApprovedAndDefaultOrderScope::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 4
b 1
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace WebDevEtc\BlogEtc\Scopes;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Scope;
8
9
class BlogCommentApprovedAndDefaultOrderScope implements Scope
10
{
11
    /**
12
     * By default only show approved blog comments.
13
     * Order by id, asc - which is what we would always want when showing comments.
14
     * We do not support comment threads/replies.
15
     *
16
     * In the admin panel we disable this scope with ::withoutGlobalScopes() or ::withoutGlobalScope(...)
17
     */
18
    public function apply(Builder $builder, Model $model)
19
    {
20
        $builder->orderBy('id', 'asc');
21
        $builder->limit(config('blogetc.comments.max_num_of_comments_to_show', 500));
22
        $builder->where('approved', true);
23
    }
24
}
25