Passed
Push — shop ( 5180ff...89f6e7 )
by Fèvre
05:07
created

Item::getItemsQueryProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Xetaravel\Http\Livewire\Admin\Shop;
4
5
use Illuminate\Contracts\Database\Query\Builder;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\Pagination\LengthAwarePaginator;
8
use Livewire\Component;
9
use Livewire\WithPagination;
10
use Xetaravel\Http\Livewire\Datatable\WithSorting;
11
use Xetaravel\Models\ShopItem;
12
13
class Item extends Component
14
{
15
    use WithPagination;
16
    use WithSorting;
17
18
    /**
19
     * The string to search.
20
     *
21
     * @var string
22
     */
23
    public string $search = '';
24
25
    /**
26
     * Used to update in URL the query string.
27
     *
28
     * @var string[]
29
     */
30
    protected $queryString = ['sortField', 'sortDirection'];
31
32
    /**
33
     * The theme used for pagination.
34
     *
35
     * @var string
36
     */
37
    protected string $paginationTheme = 'bootstrap';
38
39
    /**
40
     * Function to render the component.
41
     *
42
     * @return View
43
     */
44
    public function render()
45
    {
46
        return view('livewire.admin.shop.item', [
47
            'items' => $this->items
0 ignored issues
show
Bug Best Practice introduced by
The property items does not exist on Xetaravel\Http\Livewire\Admin\Shop\Item. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
        ]);
49
    }
50
51
    /**
52
     * Create and return the query for the items.
53
     *
54
     * @return Builder
55
     */
56
    public function getItemsQueryProperty(): Builder
57
    {
58
        $query = ShopItem::query()
59
            ->search('title', $this->search);
60
61
        return $this->applySorting($query);
62
    }
63
64
    /**
65
     * Build the query and paginate it.
66
     *
67
     * @return LengthAwarePaginator
68
     */
69
    public function getItemsProperty(): LengthAwarePaginator
70
    {
71
        return $this->itemsQuery->paginate(config('xetaravel.pagination.shop.item_per_page'));
0 ignored issues
show
Bug Best Practice introduced by
The property itemsQuery does not exist on Xetaravel\Http\Livewire\Admin\Shop\Item. Since you implemented __get, consider adding a @property annotation.
Loading history...
72
    }
73
}
74