1 | <?php |
||
2 | /** |
||
3 | * Abstract Controller. |
||
4 | * |
||
5 | * @package App\Http\Controllers |
||
6 | * |
||
7 | * @author Taylor Otwell <[email protected]> |
||
8 | * @author Nick Menke <[email protected]> |
||
9 | * @copyright 2018-2020 Nick Menke |
||
10 | * |
||
11 | * @link https://github.com/nlmenke/vertebrae |
||
12 | */ |
||
13 | |||
14 | declare(strict_types=1); |
||
15 | |||
16 | namespace App\Http\Controllers; |
||
17 | |||
18 | use App\Entities\AbstractEntity; |
||
19 | use Illuminate\Database\Eloquent\Builder as EloquentBuilder; |
||
20 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||
21 | use Illuminate\Foundation\Bus\DispatchesJobs; |
||
22 | use Illuminate\Foundation\Validation\ValidatesRequests; |
||
23 | use Illuminate\Routing\Controller; |
||
24 | use Request; |
||
25 | |||
26 | /** |
||
27 | * The base controller class. |
||
28 | * |
||
29 | * This class contains any functionality that would otherwise be duplicated in |
||
30 | * other controllers. All other controllers should extend this class. |
||
31 | * |
||
32 | * @since 0.0.0-framework introduced |
||
33 | * @since x.x.x renamed to AbstractController and added abstraction |
||
34 | */ |
||
35 | abstract class AbstractController extends Controller |
||
36 | { |
||
37 | use AuthorizesRequests; |
||
38 | use DispatchesJobs; |
||
39 | use ValidatesRequests; |
||
40 | |||
41 | /** |
||
42 | * The current locale. |
||
43 | * |
||
44 | * @since x.x.x introduced |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $currentLocale; |
||
49 | |||
50 | /** |
||
51 | * The entity instance. |
||
52 | * |
||
53 | * @since x.x.x introduced |
||
54 | * |
||
55 | * @var AbstractEntity|EloquentBuilder |
||
56 | */ |
||
57 | protected $model; |
||
58 | |||
59 | /** |
||
60 | * The number of results per page. |
||
61 | * |
||
62 | * @since x.x.x introduced |
||
63 | * |
||
64 | * @var int |
||
65 | */ |
||
66 | protected $perPage; |
||
67 | |||
68 | /** |
||
69 | * The order the results displayed. |
||
70 | * |
||
71 | * @since x.x.x introduced |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $sorting; |
||
76 | |||
77 | /** |
||
78 | * Relationships to be returned with the results. |
||
79 | * |
||
80 | * @since x.x.x introduced |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | protected $with = []; |
||
85 | |||
86 | /** |
||
87 | * Creates a new controller instance. |
||
88 | * |
||
89 | * @since x.x.x introduced |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | 28 | public function __construct() |
|
94 | { |
||
95 | 28 | $this->currentLocale = app()->getLocale(); |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
96 | |||
97 | 28 | $this->perPage = (int)Request::get('count', 10); |
|
98 | |||
99 | 28 | $sortRequest = Request::get('sorting', ['id' => 'asc']); |
|
100 | 28 | $this->sorting = [ |
|
101 | 28 | 'column' => array_keys($sortRequest)[0], |
|
102 | 28 | 'direction' => array_values($sortRequest)[0], |
|
103 | ]; |
||
104 | 28 | } |
|
105 | } |
||
106 |