Completed
Branch master (beb88f)
by Mohamed
05:24
created

SearchableCardFilter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 10
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 1
1
<?php
2
/*
3
 * This file is part of the flash.dev package.
4
 *
5
 * (c) Mohamed Alsharaf <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Moo\FlashCard\Api;
12
13
use Illuminate\Database\Eloquent\Builder;
14
use Spatie\QueryBuilder\Filters\Filter;
15
16
/**
17
 * Class SearchableCardFilter provide searchable custom filter for spatie query builder module
18
 *
19
 * @package Moo\FlashCard\Api
20
 */
21
class SearchableCardFilter implements Filter
22
{
23
    public function __invoke(Builder $query, $value, string $property): Builder
24
    {
25
        // Filter a query by search for LIKE title or content
26
        return $query->where(function ($query) use ($value) {
27
            $query->search($value);
28
        });
29
    }
30
}
31