From 75afc67f313ed17c5a9d8c648269c571acb73d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 21 Jul 2018 20:01:11 +0200 Subject: [PATCH] add backWithErrors() to controller --- app/Http/Controllers/Controller.php | 5 +++++ app/Http/Controllers/TableController.php | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 03e02a2..83b4f91 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -10,4 +10,9 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + + protected function backWithErrors($errors) + { + return back()->withInput()->withErrors($errors); + } } diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index f6b7513..8663980 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -46,14 +46,17 @@ class TableController extends Controller // Check if table name is unique for user $name = $request->get('name'); if ($u->tables()->where('name', $name)->exists()) { - return back()->withErrors([ - 'title' => "A table called \"$name\" already exists in your account.", + return $this->backWithErrors([ + 'name' => "A table called \"$name\" already exists in your account.", ]); } + // Parse and validate the columns specification + // Now we create rows, a revision pointing to them, and the table using it. + return "Ok."; } }