1 | <?php namespace Distilleries\Expendable\Http\Controllers\Admin\Base; |
||
8 | class ModelBaseController extends BaseController { |
||
9 | |||
10 | /** |
||
11 | * @var \Distilleries\Expendable\Models\BaseModel $model |
||
12 | * Injected by the constructor |
||
13 | */ |
||
14 | protected $model; |
||
15 | |||
16 | |||
17 | // ------------------------------------------------------------------------------------------------ |
||
18 | |||
19 | 240 | public function __construct(BaseModel $model, LayoutManagerContract $layoutManager) |
|
24 | |||
25 | // ------------------------------------------------------------------------------------------------ |
||
26 | // ------------------------------------------------------------------------------------------------ |
||
27 | // ------------------------------------------------------------------------------------------------ |
||
28 | |||
29 | 48 | public function putDestroy(Request $request) |
|
43 | |||
44 | // ------------------------------------------------------------------------------------------------ |
||
45 | 12 | public function postSearch(Request $request, $query = null) |
|
64 | |||
65 | 12 | protected function generateResultSearchByIds(Request $request, $query, $ids) |
|
77 | |||
78 | 8 | protected function generateResultSearch(Request $request, $query) |
|
79 | { |
||
80 | 8 | $term = $request->get('term'); |
|
81 | 8 | $page = $this->getParams($request, 'page', 1); |
|
82 | 8 | $paged = $this->getParams($request, 'page_limit', 10); |
|
83 | |||
84 | 8 | if (empty($term)) { |
|
85 | 4 | $elements = array(); |
|
86 | 4 | $total = 0; |
|
87 | 3 | } else { |
|
88 | 4 | $elements = $query->search($term)->take($paged)->skip(($page - 1) * $paged)->get(); |
|
89 | $total = $query->search($term)->count(); |
||
90 | |||
91 | } |
||
92 | |||
93 | return [ |
||
94 | 4 | 'total' => $total, |
|
95 | 1 | 'elements' => $elements |
|
96 | 3 | ]; |
|
97 | } |
||
98 | |||
99 | 12 | protected function getParams(Request $request, $key, $default_value) |
|
109 | |||
110 | } |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: