diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index 6b04aba..43718b4 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -22,7 +22,6 @@ class TableController extends Controller /** @var Table $tableModel */ $tableModel = $user->tables()->withCount(['favourites', 'forks', 'revisions', 'comments', 'proposals']) ->where('name', $table)->first(); - if ($tableModel === null) abort(404, "No such table."); // make it possible to show other revisions @@ -71,7 +70,6 @@ class TableController extends Controller /** @var Table $tableModel */ $tableModel = $user->tables()->where('name', $table)->first(); if ($tableModel === null) abort(404, "No such table."); - $this->authorize('edit', $tableModel); return view('table.conf', [ @@ -79,6 +77,33 @@ class TableController extends Controller ]); } + public function storeSettings(Request $request, User $user, string $table) + { + /** @var Table $tableModel */ + $tableModel = $user->tables()->where('name', $table)->first(); + if ($tableModel === null) abort(404, "No such table."); + $this->authorize('edit', $tableModel); + + $input = $this->validate($request, [ + 'name' => [ + 'required', + VALI_NAME, + Rule::unique('tables')->ignoreModel($tableModel), + ], + 'title' => ['required', VALI_LINE], + 'description' => ['nullable', VALI_TEXT], + 'license' => ['nullable', VALI_TEXT], + 'origin' => ['nullable', VALI_TEXT], + ]); + + $tableModel->fill($input->all()); + $tableModel->save(); + + flash()->success('Table settings saved'); + + return redirect($tableModel->viewRoute); // the route now changed + } + public function storeNew(Request $request) { /** @var User $u */ diff --git a/resources/views/table/conf.blade.php b/resources/views/table/conf.blade.php index 399281e..775b728 100644 --- a/resources/views/table/conf.blade.php +++ b/resources/views/table/conf.blade.php @@ -24,8 +24,43 @@ -