devnile /
microboard
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Microboard\Traits; |
||
| 4 | |||
| 5 | use Exception; |
||
| 6 | use Illuminate\Database\Eloquent\Model; |
||
| 7 | use Illuminate\Http\RedirectResponse; |
||
| 8 | use Illuminate\Http\Request; |
||
| 9 | use Illuminate\View\View; |
||
| 10 | use Microboard\Factory; |
||
| 11 | use Microboard\Foundations\Traits\DependencyResolverTrait; |
||
| 12 | use Microboard\Foundations\Traits\QueryResolverTrait; |
||
| 13 | use Microboard\Foundations\Traits\ViewResolverTrait; |
||
| 14 | use Microboard\Foundations\Traits\WorkingWithWidgets; |
||
| 15 | use Throwable; |
||
| 16 | |||
| 17 | trait Controller |
||
| 18 | { |
||
| 19 | use DependencyResolverTrait, |
||
| 20 | QueryResolverTrait, |
||
| 21 | WorkingWithWidgets, |
||
| 22 | ViewResolverTrait; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected string $baseName; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 28 | |||
| 29 | /** |
||
| 30 | * @var Factory |
||
| 31 | */ |
||
| 32 | private Factory $microboard; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Controller constructor. |
||
| 36 | * @param Factory $microboard |
||
| 37 | */ |
||
| 38 | public function __construct(Factory $microboard) |
||
| 39 | { |
||
| 40 | $this->baseName = str_replace('Controller', '', class_basename($this)); |
||
| 41 | $this->model = $this->getModel() ? resolve($this->getModel()) : null; |
||
| 42 | $this->microboard = $microboard; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Display a listing of the resource. |
||
| 47 | */ |
||
| 48 | public function index() |
||
| 49 | { |
||
| 50 | $this->authorize('viewAny', $this->model); |
||
| 51 | $datatable = resolve($this->getDatatable(), [ |
||
| 52 | 'attributes' => $this->attributes ?? [] |
||
| 53 | ]); |
||
| 54 | |||
| 55 | return $datatable->render($this->getViewPathFor('index'), $this->getResourceVariables('index')); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Show the form for creating a new resource. |
||
| 60 | * |
||
| 61 | * @return View |
||
| 62 | */ |
||
| 63 | public function create() |
||
| 64 | { |
||
| 65 | $this->authorize('create', $this->model); |
||
| 66 | return view($this->getViewPathFor('create'), $this->getResourceVariables('create')); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Store a newly created resource in storage. |
||
| 71 | * |
||
| 72 | * @return RedirectResponse |
||
| 73 | * @throws Throwable |
||
| 74 | */ |
||
| 75 | public function store() |
||
| 76 | { |
||
| 77 | $request = resolve($this->getStoreFormRequest()); |
||
| 78 | $variables = $this->getResourceVariables('create'); |
||
| 79 | $this->authorize('create', $this->model); |
||
| 80 | |||
| 81 | $model = $this->model->fill($this->getValidated($request)); |
||
| 82 | $this->model->saveOrFail(); |
||
| 83 | cache()->forget($variables['resourceName']); |
||
| 84 | |||
| 85 | $this->microboard->success( |
||
| 86 | trans($variables['translationsPrefix'] . '.messages.created'), |
||
| 87 | ); |
||
| 88 | |||
| 89 | if ($response = $this->created($request, $model)) { |
||
| 90 | return $response; |
||
| 91 | } |
||
| 92 | |||
| 93 | return redirect()->route("{$variables['routePrefix']}.show", $model); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The model has been created. |
||
| 98 | * |
||
| 99 | * @param Request $request |
||
| 100 | * @param Model $model |
||
| 101 | * @return mixed |
||
| 102 | */ |
||
| 103 | protected function created($request, $model) |
||
| 104 | { |
||
| 105 | // |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Display the specified resource. |
||
| 110 | * @param Request $request |
||
| 111 | * @return View |
||
| 112 | */ |
||
| 113 | public function show(Request $request) |
||
| 114 | { |
||
| 115 | $model = $this->query($request); |
||
| 116 | $this->authorize('view', $model); |
||
| 117 | |||
| 118 | return view($this->getViewPathFor('show'), $this->getResourceVariables('show', $model)); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Show the form for editing the specified resource. |
||
| 123 | * |
||
| 124 | * @param Request $request |
||
| 125 | * @return View |
||
| 126 | */ |
||
| 127 | public function edit(Request $request) |
||
| 128 | { |
||
| 129 | $model = $this->query($request); |
||
| 130 | $this->authorize('update', $model); |
||
| 131 | |||
| 132 | return view($this->getViewPathFor('edit'), $this->getResourceVariables('update', $model)); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Update the specified resource in storage. |
||
| 137 | * |
||
| 138 | * @throws Exception |
||
| 139 | */ |
||
| 140 | public function update() |
||
| 141 | { |
||
| 142 | $request = resolve($this->getUpdateFormRequest()); |
||
| 143 | $model = $this->query($request); |
||
| 144 | $this->authorize('update', $model); |
||
| 145 | $variables = $this->getResourceVariables('update'); |
||
| 146 | |||
| 147 | $model->update($this->getValidated($request)); |
||
| 148 | cache()->forget($variables['resourceName']); |
||
| 149 | |||
| 150 | $this->microboard->success( |
||
| 151 | trans($variables['translationsPrefix'] . '.messages.updated'), |
||
| 152 | ); |
||
| 153 | |||
| 154 | if ($response = $this->updated($request, $model)) { |
||
| 155 | return $response; |
||
| 156 | } |
||
| 157 | |||
| 158 | return redirect()->route("{$variables['routePrefix']}.show", $model); |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * The model has been updated. |
||
| 163 | * |
||
| 164 | * @param Request $request |
||
| 165 | * @param Model $model |
||
| 166 | * @return mixed |
||
| 167 | */ |
||
| 168 | protected function updated($request, $model) |
||
| 169 | { |
||
| 170 | // |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Remove the specified resource from storage. |
||
| 175 | * |
||
| 176 | * @param Request $request |
||
| 177 | * @return RedirectResponse |
||
| 178 | * @throws Exception |
||
| 179 | */ |
||
| 180 | public function destroy(Request $request) |
||
| 181 | { |
||
| 182 | $variables = $this->getResourceVariables('delete'); |
||
| 183 | $model = $this->query($request); |
||
| 184 | $this->authorize('update', $model); |
||
| 185 | |||
| 186 | $model->delete(); |
||
| 187 | cache()->forget($variables['resourceName']); |
||
| 188 | |||
| 189 | $this->microboard->warning( |
||
| 190 | trans($variables['translationsPrefix'] . '.messages.deleted'), |
||
| 191 | ); |
||
| 192 | |||
| 193 | if ($response = $this->deleted($request, $model)) { |
||
| 194 | return $response; |
||
| 195 | } |
||
| 196 | |||
| 197 | return redirect()->route("{$variables['routePrefix']}.index"); |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * The model has been updated. |
||
| 202 | * |
||
| 203 | * @param Request $request |
||
| 204 | * @param Model $model |
||
| 205 | * @return mixed |
||
| 206 | */ |
||
| 207 | protected function deleted($request, $model) |
||
| 208 | { |
||
| 209 | // |
||
| 210 | } |
||
| 211 | } |
||
| 212 |