Completed
Push — master ( 5c55d7...79e99a )
by Fèvre
28s queued 15s
created

WithPerPagePagination   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A applyPagination() 0 3 1
A updatedPerPage() 0 3 1
A mountWithPerPagePagination() 0 3 1
1
<?php
2
3
namespace Xetaravel\Http\Livewire\Traits;
4
5
use Illuminate\Contracts\Container\BindingResolutionException;
6
use Livewire\WithPagination;
7
use Psr\Container\NotFoundExceptionInterface;
8
use Psr\Container\ContainerExceptionInterface;
9
10
trait WithPerPagePagination
11
{
12
    use WithPagination;
13
14
    /**
15
     * Assign the perPage option from the session.
16
     *
17
     * @return void
18
     */
19
    public function mountWithPerPagePagination(): void
20
    {
21
        $this->perPage = session()->get('perPage', $this->perPage);
0 ignored issues
show
Bug Best Practice introduced by
The property perPage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
    }
23
24
    /**
25
     * Store in session the perPage option.
26
     *
27
     * @param mixed $value The value of the option perPage.
28
     *
29
     * @return void
30
     */
31
    public function updatedPerPage($value): void
32
    {
33
        session()->put('perPage', $value);
34
    }
35
36
    /**
37
     * Apply the pagination to the query.
38
     *
39
     * @param mixed $query The query to apply the pagination.
40
     *
41
     * @return mixed
42
     */
43
    public function applyPagination($query)
44
    {
45
        return $query->paginate($this->perPage);
46
    }
47
}
48